Tech Study

Write a C program to Store Information in Structure and Display it

Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include <stdio.h>
struct student
{
    char name[50];
    int roll;
    float marks;
}
    stud[2];
 
int main()
{
    int i;
 
    printf("Enter information of students:\n");
 
    // storing information
    for(i=0; i<2; ++i)
    {
        stud[i].roll = i+1;
 
        printf("\nFor roll number: %d\n",stud[i].roll);
 
        printf("Enter name: ");
        scanf("%s",stud[i].name);
 
        printf("Enter marks: ");
        scanf("%f",&stud[i].marks);
 
 
        printf("\n");
    }
 
    printf("Displaying Information:\n\n");
    // displaying information
    for(i=0; i<2; ++i)
    {
        printf("\nRoll number: %d\n",i+1);
        printf("Name: ");
        puts(stud[i].name);
        printf("Marks: %.1f",stud[i].marks);
 
        printf("\n");
    }
    return 0;
}
 

Result

Write a C program to Store Information in Structure and Display it
Write a C program to Store Information in Structure and Display it

TaggedWrite a C program to Store Information in Structure and Display it

Python Examples

Introduction: Python Examples are the basic programming concepts of python like python syntax,python data types,,python operators,python if else,python comments etc.. …

Read more

C String Functions

C String Functions perform certain operations, It provides many useful string functions which can come into action. The <string.h> header …

Read more