https://www.bybit.com/register?affiliate_id=38000&group_id=52135&group_type=1
[856x508] Get $90 Rewards

C Programming code for Sum & Average of Array Structures

Write a Modular C Programming code for Sum and Average of the Array Structures.

Read the number of students, read their information and display the details of the students:

CODE:

#include<stdio.h>
struct student
{
char name[20];
int rno;
float marks;
};
struct student s[50];
void read(struct student s[50], int n);
void avgmarks(struct student s[50], int n);
int n, i;
main()
{
printf("Enter the no. of students you want to give info: ");
scanf("%d",&n);
printf("\nEnter Details of Student %d",i+1);
read(s,n);
avgmarks(s,n);
}
void read(struct student s[50], int n)
{
for(i=0;i<n;i++)
{
printf("\nEnter the Name: ");
scanf("%s",&s[i].name);
printf("Enter the RollNo: ");
scanf("%d",&s[i].rno);
printf("Enter the Marks: ");
scanf("%f",&s[i].marks);
printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++\n");
}
}


void avgmarks(struct student s[50], int n)
{
    int sum=0;
    float avg;
    for(i=0;i<n;i++)
    {
        sum=sum+s[i].marks;
    }
    avg=sum/n;
    printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++\n");
    printf("The Sum marks of %d Students is %d",n,sum);
    printf("\nThe Avarage marks of %d Students is %f",n,avg);
    printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++\n");

}


 

OUTPUT

Enter the no. of students you want to give info: 3

Enter Details of Student 1
Enter the Name: yrjhn
Enter the RollNo: 546
Enter the Marks: 657

+++++++++++++++++++++++++++++++++++++++++++++++++

Enter the Name: tnhdcy
Enter the RollNo: 54
Enter the Marks: 57

+++++++++++++++++++++++++++++++++++++++++++++++++

Enter the Name: hghdb
Enter the RollNo: 54
Enter the Marks: 657

+++++++++++++++++++++++++++++++++++++++++++++++++

+++++++++++++++++++++++++++++++++++++++++++++++++
The Sum marks of 3 Students is 1371
The Avarage marks of 3 Students is 457.000000
+++++++++++++++++++++++++++++++++++++++++++++++++

Process returned 0 (0x0)   execution time : 13.328 s
Press any key to continue.

 

Please find some more codes of 1D Arrays, 2D Arrays, Pointers on the below page:

Top 100+ C Programming codes – KLE Technological University

 

Leave a Comment