Tuesday 26 August 2014

Filled Under: ,

C Program to Store Information of a Student Using Structure

Share
In this program, a structure(studentinfo) is created which contains name, roll and marks as its data member. Then, a structure variable( s ) is created. Then, data (name, roll and marks) is taken from user and stored in data members of structure variable s. Finally, the data entered by user is displayed.


C Program to Store Information of a Student Using Structure

C Program to Store Information of a Student Using Structure



#include <stdio.h>
struct studentinfo
{
    char name[50];
    int roll;
    float marks;
};
int main(){
    struct studentinfo std;
    printf("Enter information of students:\n\n");
    printf("Enter name: ");
    scanf("%s",std.name);
    printf("Enter roll number: ");
    scanf("%d",&std.roll);
    printf("Enter marks: ");
    scanf("%f",&std.marks);
    printf("\nDisplaying Information\n");
    printf("Name: %s\n",std.name);
    printf("Roll: %d\n",std.roll);
    printf("Marks: %.2f\n",std.marks);
    return 0;
}



Output

C Program to Store Information of a Student Using Structure