Store Information in Structure and Display it - C Programming - 👑 सार्थक मुंड S3 🤴🏻

Store Information in Structure and Display it - C Programming

Create a structure of 10 students consisting roll number, name and marks in three different subjects and display the average marks of all 10 subjects and display the average mark of 10 students.

Create a structure of 10 students consisting roll number, name and marks in three different subjects and display the average marks of all 10 subjects and display the average mark of 10 students.

#include<stdio.h>
#include<conio.h>
struct stud
{
    int rollno, s1, s2, s3, tot;
    char name[10];
    float avg;
} s[10];
void main()
{
    int i, n;
   
    printf("Enter the number of students :\n ");
    scanf("%d", &n);
    for(i = 0; i < n; i++)
    {
        printf("\nEnter roll number :\n ");
        scanf("%d", &s[i].rollno);
        printf("Enter Student name :\n ");
        scanf("%s", s[i].name);
        printf("Enter marks in 3 subjects :\n ");
        scanf("%d %d %d", &s[i].s1, &s[i].s2, &s[i].s3);
        s[i].tot = s[i].s1 + s[i].s2 + s[i].s3;
        s[i].avg = s[i].tot / 3.0;
    }
    printf("\nRoll No. Name \t\tSub1\t Sub2\t Sub3\t Total\t Average\n\n");
    for(i = 0; i < n; i++)
    {
        printf("%d \t %s \t\t %d \t %d \t %d \t %d \t %.2f \n", s[i].rollno,s[i].name,s[i].s1,s[i].s2,s[i].s3,s[i].tot,s[i].avg);
    }
    getch();
}

OutPut : 

Enter the number of students :         
 4                                                                                                                                                 
Enter roll number :                                                 
 101                                         
Enter Student name :                                                   
 Sarthak                                           
Enter marks in 3 subjects :                                                    
 98                                           
99                                       
97

Enter roll number :                                           
 102                                    
Enter Student name :                                                
 lambodar                                            
Enter marks in 3 subjects :
 98                                           
96                                          
97 

Enter roll number :                                                  
 103                 
Enter Student name :                                                     
 Sujata                                            
Enter marks in 3 subjects :
 98                                            
99                                           
97

Enter roll number :                                                   
 104                                        
Enter Student name :                                                   
 Rubyyy                                           
Enter marks in 3 subjects :
 98  
96                                       
97

Roll No. Name           Sub1     Sub2    Sub3    Total   Average
101      Sarthak        98       99      97      294     98.00
102      lambodar       98       96      97      291     97.00
103      Sujata         98       99      97      294     98.00 
104      Rubyyy         98       96      97      291     97.00

Create a structure of 10 students consisting roll number, name and marks in three different subjects and display the average marks of all 10 subjects and display the average mark of 10 students.
OUTPUT

Must Read :-

  1. Blogger Tutorial
  2. C Programs
  3. C++ Programs
  4. Java Programs
  5. Python Programs
  6. Programming Notes 
  7. Questions & Answers
  8. My Codes : HTML, CSS & JS
Previous article
This Is The Newest Post
Next article

1 Comments

Articles Ads

Articles Ads 1

Articles Ads 2

Advertisement Ads