-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArray_of_Structures.cpp
50 lines (43 loc) · 1.34 KB
/
Array_of_Structures.cpp
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
44
45
46
47
48
49
50
#include<stdio.h>
#include<conio.h>
#include<string.h>
typedef struct
{
int id;
char name[20];
float percentage;
}student;
void EnterDetails(student[],int); /*Function Declaration of the Function to Add Student Details*/
int main()
{
student s[10]; /*Declaration of the Structure Variables*/
int number, i;
printf("\nEnter the Number of Students :: ");
scanf_s("%d", &number);
EnterDetails(s, number); /*Entering the Details of the Students through a Function (Call by Reference)*/
/*Displaying the Details of the Student through a For Loop*/
printf("\nStudent Details are as follows :: ");
for (i = 0; i < number; i++)
{
printf("\n************Student No %d :: **********",i+1);
printf("\n ID :: %d", s[i].id);
printf("\n Name :: %s", s[i].name);
printf("\n Percentage :: %f", s[i].percentage);
}
_getch();
return 0;
}
void EnterDetails(student s[], int n)
{
for (int i = 0; i < n; i++)
{
printf("\n**************Enter the Details for Student %d :: ***********",i+1); /*User Entering the Details into the Structure Variables*/
printf("\nID/Roll No :: ");
scanf_s("%d", &s[i].id);
getchar(); /*To Consume the unwanted new line character*/
printf("Name :: ");
gets_s(s[i].name, 20);
printf("Percentage :: ");
scanf_s("%f", &s[i].percentage);
}
}