C program to store information of n student using structure - wordsclank.in

Tuesday 13 March 2018

C program to store information of n student using structure

A structure is a user defined data type available in C that helps to combine a lot of different data type under a single name which is easier to handle.
For example: A structure student which will store roll number of integer data type, name of character data type, marks of float type.
structure,structure in c

Problem statement:

C program to store information of n student using structure



Source code

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include

struct student
{
 char name[100];
 int roll;
 float mark;
}str[100];

int main()
{
 int n, i;
 printf("Enter the number of student: ");
 scanf("%d",&n);
 
 printf("Enter the informations of the student:\n");
 
 for(i=0;i<n;i++)
 {
  str[i].roll = i+1;
  
  printf("For roll number %d \n",str[i].roll);
  
  printf("Enter name: ");
  scanf("%s", str[i].name);
  
  printf("Enter marks: ");
  scanf("%f",&str[i].mark);
  
  printf("\n");
 }
 
 printf("The information of %d students are as follows:\n",n);
 for(i=0;i<n;i++)
 {
  printf("Roll number : %d\n",i+1);
  printf("Name:");
  puts(str[i].name);
  printf("Marks:%f",str[i].mark);
  printf("\n");
 }
 return 0;
}



Output

structure, structure in c

2 comments: