Saturday, April 9, 2022

C program to create an array of student names

This program is based on C programming String and an Array concept.


Problem definition: Write a C program to create an array of student names.

//C Program to create an array of student names

#include<stdio.h>

int main(){
	char name[5][20]; 
	//This can store 5 names; maximum 20 characters in each name
	
	int i;
	//Logic to Read name of 5 students
	for(i=0; i<5; i++){
		printf("Enter name %d:", i+1);
		gets(name[i]);
	}
	printf("List of student names stored: \n");
	//Logic to print name of 5 students
	for(i=0; i<5; i++){
		printf("%s \n", name[i]);
	}
	return 0;
}

Output of the program

Enter name 1:Amit
Enter name 2:Sunit
Enter name 3:Kamlesh
Enter name 4:Bhargav
Enter name 5:Alpesh

List of student names stored:
Amit
Sunit
Kamlesh
Bhargav
Alpesh

* * *





No comments:

Post a Comment