Friday, 15 April 2016

C Program To Store Multiple Students Information of Using Structure

Problem :- Write A C Program To Store Multiple Students Information of Using Structure Like (Roll No. ,Name ,Marks) .

What Is Structure

Structure is a user-defined data type in C which allows you to combine different data types to store a particular type of record. Structure helps to construct a complex data type in more meaningful way. It is somewhat similar to an Array. The only difference is that array is used to store collection of similar datatypes while structure can store collection of any type of data.

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 student information using structure we are taking input as Roll Number ,Name & Marks .But you can Store multiple Student information as you want 

Structure Declare :-

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

Storing in Structure :-

for(i=0;i<n;i++)
    {
        printf("\nRoll No. : ");
scanf("%d",&(s[i].roll));
        
printf("Name : ");
        scanf("%s",s[i].name);
        
printf("Marks : ");
        scanf("%f",&(s[i].marks));
    }

Displaying Store Information :-

for(i=0;i<n;i++)
       {
      printf("\nRoll No. : %d",s[i].roll);
      printf("\nName : %s",s[i].name);
      printf("\nMarks : %f",s[i].marks);
printf("\n\n");
    }



Solution :-

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

int main()
{
  //Ghanendra Yadav
    int i,n;
    
printf("Enter The Total Number Of Student : ");
    scanf("%d",&n);
    
    struct student s[n];
 
printf("\nEnter Information of students (Marks Sholud be Float Like 78.00):\n");
    
for(i=0;i<n;i++)
    {
        printf("\nRoll No. : ");
scanf("%d",&(s[i].roll));
        
printf("Name : ");
        scanf("%s",s[i].name);
        
printf("Marks : ");
        scanf("%f",&(s[i].marks));
    }
    
    printf("\nDisplaying All Information of Students :\n");
    
for(i=0;i<n;i++)
    {
      printf("\nRoll No. : %d",s[i].roll);
      printf("\nName : %s",s[i].name);
      printf("\nMarks : %f",s[i].marks);
printf("\n\n");
    }
   return 0;
}

Output:-

C Program To Store Multiple Students Information of Using Structure

No comments:
Write comments

Recommended Posts × +