Program to enter 5 name in array and print output | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Program to enter 5 name in array and print output

I tried this code #include <stdio.h> int main() { int a[5],r; for(r=0;r<5;r++) { printf("enter name"); scanf("%s",&a[r]); } for(r=0;r<5;r++) { printf("%s\n",a[r]); } return 0; }

27th Oct 2019, 3:20 PM
Alfred Monir
Alfred Monir - avatar
2 Answers
0
You need a 2 dimensions char array to do that (not int). int is used for saving numbers (whole numbers), for saving string use char array.
27th Oct 2019, 4:19 PM
Ipang
+ 2
Ipang I got it, after using two dimensional char array I got the output, The correct code for this after char array is- #include <stdio.h> int main() { char a[5][100]; int r; for(r=0;r<5;r++) { printf("enter name"); scanf("%s",&a[r]); } for(r=0;r<5;r++) { printf("%s\n",a[r]); } return 0; }
27th Oct 2019, 4:27 PM
Alfred Monir
Alfred Monir - avatar