Given a list of marks ranging from 0 to 100, write a program to compute and print the number of students:
(a) who have obtained more than 80 marks,
(b) who have obtained more than 60 marks,
(c) who have obtained more than 40 marks,
(d) who have obtained 40 or less marks,
(e) in the range 81 to 100,
(f) in the range 61 to 80,
(g) in the range 41 to 60, and
(h) in the range 0 to 40.
The program should use a minimum number of if statements.
#include <stdio.h>
void main()
{
int n,i,marks,count=0,count1=0,count2=0,count3=0,count4=0,count5=0,count6=0,count7=0;
clrscr();
printf("Enter the number of Students:");
scanf("%d",&n);
for(i=1;i<=n;++i)
{
printf("Enter marks\n");
scanf("%d",&marks);
if(marks>80)
count++;
if(marks>60)
count1++;
if(marks>40)
count2++;
if(marks<40)
count3++;
if(marks>80)
count4++;
else if(marks>60)
count5++;
else if(marks>40)
count6++;
else if(marks<=40)
count7++;
}
printf("More than 80 marks = %d\nMore than 60 marks =%d\nMore than 40 marks\
= %d\n40 or Less marks = %d\n",count,count1,count2,count3);
printf("Range 81 to 100 marks = %d\nRange 61 to 80 marks =%d\nRange 41 to 60 \
marks = %d\nRange 0 to 40 marks = %d",count4,count5,count6,count7);
getch();
}
(a) who have obtained more than 80 marks,
(b) who have obtained more than 60 marks,
(c) who have obtained more than 40 marks,
(d) who have obtained 40 or less marks,
(e) in the range 81 to 100,
(f) in the range 61 to 80,
(g) in the range 41 to 60, and
(h) in the range 0 to 40.
The program should use a minimum number of if statements.
#include <stdio.h>
void main()
{
int n,i,marks,count=0,count1=0,count2=0,count3=0,count4=0,count5=0,count6=0,count7=0;
clrscr();
printf("Enter the number of Students:");
scanf("%d",&n);
for(i=1;i<=n;++i)
{
printf("Enter marks\n");
scanf("%d",&marks);
if(marks>80)
count++;
if(marks>60)
count1++;
if(marks>40)
count2++;
if(marks<40)
count3++;
if(marks>80)
count4++;
else if(marks>60)
count5++;
else if(marks>40)
count6++;
else if(marks<=40)
count7++;
}
printf("More than 80 marks = %d\nMore than 60 marks =%d\nMore than 40 marks\
= %d\n40 or Less marks = %d\n",count,count1,count2,count3);
printf("Range 81 to 100 marks = %d\nRange 61 to 80 marks =%d\nRange 41 to 60 \
marks = %d\nRange 0 to 40 marks = %d",count4,count5,count6,count7);
getch();
}
No comments:
Post a Comment