Friday, 15 April 2016

C Program To Store Student Information Like (Name, Roll & Marks) In C Using Structure

Problem :- Write A C Program To Store Student Information Like (Name, Roll & Marks) Of Single Student Using Structure 

What Is Structure


Structure is a user-defined data type in C . Structure is used to represent a record. Suppose you want to store record of Student which consists of student name, address, roll number and age. You can define a structure to hold this information.

Defining a structure

struct keyword is used to define a structure. struct define a new data type which is a collection of different type of data.

Syntax :

struct structure_name
{
//Statements
};

Logic :- Here We Are storing a single student information like roll number ,name and marks Not using for loop
So just define a structure like Below.

struct student
{
    char name[50];
    int roll;
    float marks;
};

Then Store the information in structure See the Example how Store the info in structure 

printf("Enter The Information of Students :\n\n");
    
printf("Enter Name : ");
scanf("%s",s.name);
    
printf("Enter Roll No. : ");
scanf("%d",&s.roll);
    
printf("Enter marks : ");
scanf("%f",&s.marks); 

And Then Displaying the Stored Information .

printf("Name: %s\n",s.name);
printf("Roll: %d\n",s.roll);
printf("Marks: %.2f\n",s.marks);

See The Below Problem For Handling a multiple Student Data Using Array Like Name ,Roll Number and Marks .

Try This C Program To Store Multiple Students Information of Using Structure

Solution :-

#include <stdio.h>
struct student
{
    char name[50];
    int roll;
    float marks;
};
int main()
{
  //Ghanendra Yadav
    struct student s;
    
printf("Enter The Information of Students :\n\n");
    
printf("Enter Name : ");
    scanf("%s",s.name);
    
printf("Enter Roll No. : ");
    scanf("%d",&s.roll);
    
    printf("Enter marks : ");
    scanf("%f",&s.marks);
    
    printf("\nDisplaying Information\n");
    
printf("Name: %s\n",s.name);
    printf("Roll: %d\n",s.roll);
    printf("Marks: %.2f\n",s.marks);
    return 0;
}

Output:-

C Program To Store Student Information Like (Name, Roll & Marks) In C Using Structure

No comments:
Write comments

Recommended Posts × +