Professional Documents
Culture Documents
#include <stdio.h>
struct student
{
char name[50];
int roll;
float marks;
} s;
int main()
{
printf("Enter information:\n");
printf("Displaying Information:\n");
printf("Name: ");
puts(s.name);
return 0;
}
Output
Enter information:
Enter name: Jack
Enter roll number: 23
Enter marks: 34.5
Displaying Information:
Name: Jack
Roll number: 23
Marks: 34.5
C Program to Store Information of Students Using Structure
#include <stdio.h>
struct student
{
char name[50];
int roll;
float marks;
} s[10];
int main()
{
int i;
// storing information
for(i=0; i<10; ++i)
{
s[i].roll = i+1;
printf("\n");
}
printf("Displaying Information:\n\n");
// displaying information
for(i=0; i<10; ++i)
{
printf("\nRoll number: %d\n",i+1);
printf("Name: ");
puts(s[i].name);
printf("Marks: %.1f",s[i].marks);
printf("\n");
}
return 0;
}
Output
Roll number: 1
Name: Tom
Marks: 98
.
.
.
calculate mean of three subjects of each person
#include <stdio.h>
#define N 4
struct student{
char name[20];
int eng;
int math;
int phys;
double mean;
};
int main(void)
{
int i, j;
return (0);
}
(Execution result)
$ ./a.out
Jack: Eng = 82 Math = 72 Phys = 58: Mean = 70.7
Young: Eng = 77 Math = 82 Phys = 79: Mean = 79.3
Steeve: Eng = 52 Math = 62 Phys = 39: Mean = 51.0
Mark: Eng = 61 Math = 82 Phys = 88: Mean = 77.0
$