4/15/2016

C Program To Store Information of Students Using Structure

Problem:- C Program To Store Information of Students Using Structure or Write A C Program To Store Multiple Students Information of Using Structure Like (Roll No., Name, Marks) or c program to store information of 10 students using structure or c program for student mark sheet using structure or c program using structures employee details or student mark list program in c using an array or c program using structure to find students grades in a class or c program for student details using files or simple c program for student mark list or c program using structure array.

What Is Structure

The 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 a more meaningful way. It is somewhat similar to an Array. The only difference is that array is used to store a collection of similar datatypes while structure can store a collection of any type of data.

The structure is used to represent a record. Suppose you want to store a 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 from 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()
{
/* Program By Ghanendra Yadav
    Visit http://www.programmingwithbasics.com/
*/
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 Information of Students Using Structure


You May Also See


1. C Program To Check Character Is Uppercase, Lowercase Alphabet Or A Digit Or A Special Symbol

2. C Program To Find Greatest Among Three Numbers

3. C Program For Checking You Are Eligible For Voting Or Not

4. C Program For Finding Greater Between Two Number

5. C Program For Checking Number Is Even Or Odd

6. C Program For Check Leap Year Or Not Using If /Else Statement

7. C Program For Check Character Is Vowel Or Not Using If Else Statement

8. C Program To Check Given Date Month And Year Is Correct or Not Using If Else Statements




No comments:

Post a Comment