126k views
10 votes
Write a program to accept a name and roll number of 5 student using structure in C​

2 Answers

4 votes

CODE

#include <stdio.h>

#include <string.h>

struct student {

char name[50];

int roll;

};

int main() {

struct student student1;

strcpy(student1.name, "Chris Hansen");

student1.roll = 38;

printf("Name: %s\\Roll number: %d\\", student1.name, student1.roll);

struct student student2;

strcpy(student2.name, "Edip Yuksel");

student2.roll = 19;

printf("Name: %s\\Roll number: %d\\", student2.name, student2.roll);

struct student student3;

strcpy(student3.name, "Skeeter Jean");

student3.roll = 57;

printf("Name: %s\\Roll number: %d\\", student3.name, student3.roll);

struct student student4;

strcpy(student4.name, "Sinbad Badr");

student4.roll = 114;

printf("Name: %s\\Roll number: %d\\", student4.name, student4.roll);

struct student student5;

strcpy(student5.name, "Titus Alexius");

student5.roll = 76;

printf("Name: %s\\Roll number: %d\\", student5.name, student5.roll);

return 0;

}

DISPLAY

Name: Chris Hansen

Roll number: 38

Name: Edip Yuksel

Roll number: 19

Name: Skeeter Jean

Roll number: 57

Name: Sinbad Badr

Roll number: 114

Name: Titus Alexius

Roll number: 76

Step-by-step explanation

Use string.h to access string functions for names.

Create a struct outside of the main on student name and roll number.

strcpy works for strings.

Create for 1 student and copy and paste for the others.

Display the name and roll number for each student.

User Hedfol
by
5.4k points
8 votes

Answer:

This C program is to store and display the information of a student using structure i.e. to store and display the roll number,name,age and fees of a student using structure.

Basically one should know how to write the syntax of a structure and the rest is just implementation of the programs done so far.

If you yet need a dry run of the program or any other query, then kindly leave a comment in the comment box or mail me, I would be more than happy to help you.

User Schottky
by
6.0k points