/*
Write C program to store marks scored for first test of subject 'Data Structures and
Algorithms' for N students. Compute
I. The average score of class
ii. Highest score and lowest score of class
iii. Marks scored by most of the students
iv. list of students who were absent for the test
*/
#include<stdio.h>
struct student
{
int marks;
int attd;
};
int main()
{
int n,i;
int ch;
printf("\nEnter total number of students:");
scanf("%d",&n);
struct student se[n];
for(i=1;i<=n;i++)
{
printf("\nroll no. %d \n",i);
printf("attendence: 1.present 2.absent");
printf("\nEnter your choice:");
scanf("%d",&ch);
if(ch==1)
{
se[i].attd=1;
printf("\nEnter DSA marks: ");
scanf("%d",&se[i].marks);
}
else
{
se[i].attd=0;
se[i].marks=0;
}
}
for(i=1;i<=n;i++)
{
printf("\nRoll number is: %d\tattendence is: %d\tmarks are:%d",i,se[i].attd,se[i].marks);
}
//The average score of class
int sum=0;
float avg=0;
int cnt=0;
for(i=1;i<=n;i++)
{
if(se[i].attd==1)
{
sum=sum+se[i].marks;
cnt++;
}
}
avg=sum/cnt;
printf("\n\nThe average score of class is : %f",avg);
//Highest score and lowest score of class
int max=0;
int min=99;
for(i=1;i<=n;i++)
{
if(se[i].attd==1)
{
if(min>se[i].marks)
{
min=se[i].marks;
}
if(max<se[i].marks)
{
max=se[i].marks;
}
}
}
printf("\n\nHighest score is: %d and lowest score is: %d",max,min);
//Marks scored by most of the students
int j;
int m=0;
int val;
cnt=0;
for(i=1;i<=n;i++)
{
cnt=0;
for(j=1;j<=n;j++)
{
if(se[i].marks==se[j].marks)
cnt++;
}
if(m<cnt)
{
m=cnt;
val=se[i].marks;
}
}
printf("\n\nMarks scored by most of the students is: %d and no. of student is: %d",val,m);
//list of students who were absent for the test
cnt=0;
printf("\n\nlist of students who were absent for the test:");
for(i=1;i<=n;i++)
{
if(se[i].attd==0)
{
printf("\nRoll number %d is absent",i);
cnt++;
}
}
printf("\ntotal number of absent students is: %d\n",cnt);
return 0;
}
/*
output-
Enter total number of students:5
roll no. 1
attendence: 1.present 2.absent
Enter your choice:1
Enter DSA marks: 60
roll no. 2
attendence: 1.present 2.absent
Enter your choice:2
roll no. 3
attendence: 1.present 2.absent
Enter your choice:1
Enter DSA marks: 40
roll no. 4
attendence: 1.present 2.absent
Enter your choice:2
roll no. 5
attendence: 1.present 2.absent
Enter your choice:1
Enter DSA marks: 80
Roll number is: 1 attendence is: 1 marks are:60
Roll number is: 2 attendence is: 0 marks are:0
Roll number is: 3 attendence is: 1 marks are:40
Roll number is: 4 attendence is: 0 marks are:0
Roll number is: 5 attendence is: 1 marks are:80
The average score of class is : 60.000000
Highest score is: 80 and lowest score is: 40
Marks scored by most of the students is: 0 and no. of student is: 2
list of students who were absent for the test:
Roll number 2 is absent
Roll number 4 is absent
total number of absent students is: 2
*/
Write C program to store marks scored for first test of subject 'Data Structures and
Algorithms' for N students. Compute
I. The average score of class
ii. Highest score and lowest score of class
iii. Marks scored by most of the students
iv. list of students who were absent for the test
*/
#include<stdio.h>
struct student
{
int marks;
int attd;
};
int main()
{
int n,i;
int ch;
printf("\nEnter total number of students:");
scanf("%d",&n);
struct student se[n];
for(i=1;i<=n;i++)
{
printf("\nroll no. %d \n",i);
printf("attendence: 1.present 2.absent");
printf("\nEnter your choice:");
scanf("%d",&ch);
if(ch==1)
{
se[i].attd=1;
printf("\nEnter DSA marks: ");
scanf("%d",&se[i].marks);
}
else
{
se[i].attd=0;
se[i].marks=0;
}
}
for(i=1;i<=n;i++)
{
printf("\nRoll number is: %d\tattendence is: %d\tmarks are:%d",i,se[i].attd,se[i].marks);
}
//The average score of class
int sum=0;
float avg=0;
int cnt=0;
for(i=1;i<=n;i++)
{
if(se[i].attd==1)
{
sum=sum+se[i].marks;
cnt++;
}
}
avg=sum/cnt;
printf("\n\nThe average score of class is : %f",avg);
//Highest score and lowest score of class
int max=0;
int min=99;
for(i=1;i<=n;i++)
{
if(se[i].attd==1)
{
if(min>se[i].marks)
{
min=se[i].marks;
}
if(max<se[i].marks)
{
max=se[i].marks;
}
}
}
printf("\n\nHighest score is: %d and lowest score is: %d",max,min);
//Marks scored by most of the students
int j;
int m=0;
int val;
cnt=0;
for(i=1;i<=n;i++)
{
cnt=0;
for(j=1;j<=n;j++)
{
if(se[i].marks==se[j].marks)
cnt++;
}
if(m<cnt)
{
m=cnt;
val=se[i].marks;
}
}
printf("\n\nMarks scored by most of the students is: %d and no. of student is: %d",val,m);
//list of students who were absent for the test
cnt=0;
printf("\n\nlist of students who were absent for the test:");
for(i=1;i<=n;i++)
{
if(se[i].attd==0)
{
printf("\nRoll number %d is absent",i);
cnt++;
}
}
printf("\ntotal number of absent students is: %d\n",cnt);
return 0;
}
/*
output-
Enter total number of students:5
roll no. 1
attendence: 1.present 2.absent
Enter your choice:1
Enter DSA marks: 60
roll no. 2
attendence: 1.present 2.absent
Enter your choice:2
roll no. 3
attendence: 1.present 2.absent
Enter your choice:1
Enter DSA marks: 40
roll no. 4
attendence: 1.present 2.absent
Enter your choice:2
roll no. 5
attendence: 1.present 2.absent
Enter your choice:1
Enter DSA marks: 80
Roll number is: 1 attendence is: 1 marks are:60
Roll number is: 2 attendence is: 0 marks are:0
Roll number is: 3 attendence is: 1 marks are:40
Roll number is: 4 attendence is: 0 marks are:0
Roll number is: 5 attendence is: 1 marks are:80
The average score of class is : 60.000000
Highest score is: 80 and lowest score is: 40
Marks scored by most of the students is: 0 and no. of student is: 2
list of students who were absent for the test:
Roll number 2 is absent
Roll number 4 is absent
total number of absent students is: 2
*/
No comments:
Post a Comment