Skip to main content

Structures abov below avg77

Structures abov below avg
#include<stdio.h>

struct student

{

char name [100];

char usn [20];

float marks;

};

void main()

{

int i,j,k,m,n,aboveavg[100],belowavg[100];

float total=0.0,avg=0.0;

struct student s[100];

printf("enter number of students\n");

scanf("%d",&n);

for(i=0;i<n;i++)

{

printf("enter the details of students%d\n",i+1);

printf("enter name\n");

scanf("%s",s[i].name);

printf("enter usn\n");

scanf("%s",s[i].usn);

printf("enter marks\n");

scanf("%f",&s[i].marks);

total+=s[i].marks;

}

printf("enter the details of students\n");

printf("name\t\t usn\t\t marks\n");

for(i=0;i<n;i++)

printf("%s\t\t %s\t\t %f\n",s[i].name,s[i].usn,s[i].marks);

avg=total/n;

printf("avg=%f\n",avg);

j=0;

k=0;

for(i=0;i<n;i++)

{

if(s[i].marks>avg)

aboveavg[j++]=i;

else

belowavg[k++]=i;

}

printf("students scoring aboveavg\n");

for(i=0;i<j;i++)

printf("%s\%f\n",s[aboveavg[i]].name,s[aboveavg[i]].marks);

printf("students scoring belowavg\n");

for(i=0;i<k;i++)

printf("%s\t %f\n",s[belowavg[i]].name,s[belowavg[i]].marks);

}
Structures abov below avg ALG

Start

Declare the required variables

Read number of students as n

for each student read the name, usn and marks and store it in structure stud

stud.name = name

stud.usn = usn

stud.marks = marks

total = total + marks

avg = total/n

j = 0

k = 0

for i = 0 through n-1 do

      if(stud[i].marks > avg)

             aboveavg[j++] = i

      else belowavg[k++] = i

Display students above the average

for i = 0 through j -1 do

display stud[aboveavg[i]].name,  stud[aboveavg[i]].marks

Display students below the average

for i = 0 through k -1 do

display stud[belowavg [i]].name,  stud[belowavg [i]].marks

Stop



Comments

Popular posts from this blog

Raju is a Civil Engineer. He is writing software to automate his work. As a part of his requirement, he wants to calculate the circle diameter, circumference, and area. Help Raju to complete his task. Get radius as input.

OUTPUT

Write functions to implement string operations such as compare, concatenate, string length. Convince the parameter passing techniques Program and Algorithm Computer Science Engineering VTU

STRINGconcatenation #include<stdio.h> #include<stdlib.h> int length (char str[]); int compare (char str1[],char str2[]); void concatenate (char str1[],char str2[]); void main() { char str1[30],str2[30]; int choice,a,i,j; printf("enter 1-string comparision\n"); printf("enter 2-string length\n"); printf("enter 3-string concatenation\n"); printf("enter 4-exit\n"); scanf("%d",&choice); switch(choice) { case 1:printf("enter string 1\n"); scanf("%s",str1); printf("enter string 2\n"); scanf("%s",str2); a=compare(str1,str2); if(a==0) { printf("%s and%s are identical\n",str1,str2); } else { printf("%s and%s are not identical\n",str1,str2); } break; ...