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; }
2 ответов
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.
+ 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;
}