Wednesday, October 3, 2018

CPL 13 - COMPUTE AVERAGE- MARKS

13. Implement structures to read, write, compute average- marks and the students scoring above and below the average marks for a class of N students.

ALGORITHM:

STEP 1: [input number of students]
Read n

STEP 2: [input details of students ie.name and marks]
Read name,m1,m2,m3

STEP 3: [ Calculate total and average]
For <- i=0 to n
s[i].total=(s[i].m1+s[i].m2+s[i].m3);
T=T+s[i].total;
AVG=T/N;

STEP 4: [Find students above and below average]
for <- i=0 to n
aboveavg[j]=i;
j++;
else
belowavg[k]=i;
k++;

STEP 5: [Finished]

STOP

FLOWCHART:


PROGRAM:

#include<stdio.h>

struct stud
{
int rollno, s1, s2, tot ;
char name[10] ;
float avg ;
}s[10] ;

float compute( struct stud S[], int n )
{
int i;
float sum=0 ;
for ( i = 0 ; i < n ; i++ )
{
sum = sum + S[i].avg ;
}
return (sum/n);
}

void display( struct stud s )
{
printf("%d \t %s \t\t %d \t %d \t %d \t %.2f \n", s.rollno,s.name,s.s1,s.s2,s.tot,s.avg);
}

void main()
{
int i, n ;
float mean;
printf("Enter the number of students : ") ;
scanf("%d", &n) ;
for(i = 0 ; i < n ; i++)
{
printf("\nEnter the roll number : ") ;
scanf("%d", &s[i].rollno) ;
printf("\nEnter the name : ") ;
scanf("%s", s[i].name) ;
printf("\nEnter the marks in 2 subjects : ") ;
scanf("%d %d", &s[i].s1, &s[i].s2) ;

s[i].tot = s[i].s1 + s[i].s2 ;
s[i].avg = s[i].tot / 2.0 ;
}

mean = compute( s,n);
printf("\nBelow Average Students\n");
printf("\nRoll No. Name \t\tSub1\t Sub2\t Total\t Average\n\n") ;
for(i = 0 ; i < n ; i++)
{
if( s[i].avg < mean )
display(s[i]);
}

printf("\nAbove Average Students\n");
printf("\nRoll No. Name \t\tSub1\t Sub2\t Total\t Average\n\n") ;
for(i = 0 ; i < n ; i++)
{
if( s[i].avg >= mean )
display(s[i]);
}

}

OUTPUT:

No comments:

Post a Comment