Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

WAP to create Database using array of structure & display it in C

#include <stdio.h>
struct student {
    char firstName[50];
    int roll;
    float marks;
} s[5];

int main() {
    int i;
    printf("Enter information of students:
");

    // storing information
    for (i = 0; i < 5; ++i) {
        s[i].roll = i + 1;
        printf("
For roll number%d,
", s[i].roll);
        printf("Enter first name: ");
        scanf("%s", s[i].firstName);
        printf("Enter marks: ");
        scanf("%f", &s[i].marks);
    }
    printf("Displaying Information:

");

    // displaying information
    for (i = 0; i < 5; ++i) {
        printf("
Roll number: %d
", i + 1);
        printf("First name: ");
        puts(s[i].firstName);
        printf("Marks: %.1f", s[i].marks);
        printf("
");
    }
    return 0;
}
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #WAP #create #Database #array #structure #display #C
ADD COMMENT
Topic
Name
5+3 =