01/04/2022

Write a C Program to Display Student Details Using Structure

Write a C Program to Display Student Details Using Structure. In this problem Statement, the User has to Enter the Student details manually Ie. Student Name, Student Roll Number & Student Marks and We have to print the Student details using in same respectful in the same manner as Input using Structure (Name, Roll & Marks).

Before coding, we must know the What is Structure, the Definition of Structure and the Syntax of the Structure.

Write a C Program to Display Student Details Using Structure

What Is Structure


The structure is a user-defined data type in C. Structure is used to represent a record. Suppose you want to store a student record consisting of the student's 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 defines a new data type, a collection of different data types. Below is the Syntax of the Structure for the C Program to Display Student Details Using Structure.

Syntax of Structure

struct structure_name
{
//Statements
};

Below is the C Program to display the student name, roll number and marks.

C Program to Display Student Details Using Structure

#include <stdio.h>
struct student
{
    char name[50];
    int roll;
    float marks;
};
int main()
{
    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;
}

The output of the Program


The Output of the Program to Display Student Details Using Structure

The Logic for C Program for Storing the Student Details 


Here we are Defining the Structure and the Data Types with Structure.
struct student
{
    char name[50];
    int roll;
    float marks;
};
Here we are storing single student information ie, Student Name, Student Roll Number and Student Marks without using the FOR LOOP.
printf("Enter The Information of Students :\n\n");

scanf("%s",s.name);
scanf("%d",&s.roll);
scanf("%f",&s.marks); 
Here we are Printing the Student Details, Student Name, Student Roll Number and Student Marks without using any LOOPS.
printf("Name: %s\n",s.name);
printf("Roll: %d\n",s.roll);
printf("Marks: %.2f\n",s.marks);

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

Related to Structure Program in C


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

1 comment: