google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a c program to demonstrate array of structure - 2nd puc computer science

Write a c program to demonstrate array of structure

write a c program to implement array of structure

Write a c program to demonstrate array of structure

#include<stdio.h>

#include<conio.h>

struct employee

{

int empid;

char name[20];

char designation[15];

}e[1000];

void main()

{

int i,n;

clrscr();

printf("How many employees? ");

scanf("%d",&n);

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

{

printf("Enter the employee id, name, and designation of employee %d\n",i+1);

scanf("%d",&e[i].empid);

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

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

}

printf("\nEmployee Information\n");

printf("---------------------------------------\n");

printf("empid\tname\tdesignation\n");

printf("---------------------------------------\n");

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

{

printf("%d\t",e[i].empid);

printf("%s\t",e[i].name);

printf("%s\t\n",e[i].designation);

}

printf("---------------------------------------\n");

getch();

}

Output:

How many employees? 2

Enter the employee id, name, and designation of employee 1                     

1                                                                              

Swaroop                                                                        

Manager                                                                         

Enter the employee id, name, and designation of employee 2                     

2                                                                              

Raj                                                                             

Assistant                                                                      

                                                                               

Employee Information                                                           

---------------------------------------

empid   name    designation                                             

---------------------------------------

1       Swaroop Manager                                                        

2       Raj     Assistant                                                      

--------------------------------------- 

Write a program to create a marks list of the students

student details using array of structure in c

#include<stdio.h>

#include<conio.h>

void main()

{

struct student

{

int rollno;

int m1,m2,m3;

float per;

}s[100];

int i,total,n;

clrscr();

printf("Enter the number of students: \n");

scanf("%d",&n);

printf("Kindly provide the information of %d students\n",n);

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

{

printf("Enter the roll number of student %d: ",i+1);

scanf("%d",&s[i].rollno);

printf("Enter the subject 1 marks: ");

scanf("%d",&s[i].m1);

printf("Enter the subject 2 marks: ");

scanf("%d",&s[i].m2);

printf("Enter the subject 3 marks: ");

scanf("%d",&s[i].m3);

}

printf("-------------------------------------------------------\n");

printf("Rollno\tSub1\tSub2\tSub3\tPercentage\n");

printf("-------------------------------------------------------\n");

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

{

total=s[i].m1+s[i].m2+s[i].m3;

s[i].per=total/3.0;

printf("%d\t%d\t%d\t%d\t%f\n",s[i].rollno,s[i].m1,s[i].m2,s[i].m3,s[i].per);

}

printf("-------------------------------------------------------\n");

getch();

}

Output:

Enter the number of students:

3                                                                              

Kindly provide the information of 3 students                                   

Enter the roll number of student 1: 1                                          

Enter the subject 1 marks: 56                                                  

Enter the subject 2 marks: 65                                                  

Enter the subject 3 marks: 60                                                  

Enter the roll number of student 2: 2                                          

Enter the subject 1 marks: 77                                                  

Enter the subject 2 marks: 78                                                  

Enter the subject 3 marks: 70                                                  

Enter the roll number of student 3: 3                                          

Enter the subject 1 marks: 90                                                  

Enter the subject 2 marks: 96                                                  

Enter the subject 3 marks: 91                                                  

-------------------------------------------------------            

Rollno  Sub1    Sub2    Sub3    Percentage                                     

-------------------------------------------------------

1       56      65      60      60.000000                                       

2       77      78      70      75.000000                                      

3       90      96      91      92.000000                                                                   

-------------------------------------------------------

Write a c program to demonstrate array of structure Write a c program to demonstrate array of structure Reviewed by Vision Academy on December 14, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.