C Language | Arrays 20

Double dimension character array

char n[20]: one string of size 20(19+1)

char n[10][20]: 10 strings each of size 20(19+1).

Question:1
C program to take input for 5 names and display them.
Sol:

#include<stdio.h>
int main()
{
    char n[5][20];
    int i;
    /* clrscr(); */
    /* input */
    for(i=0;i<5;i++)
    {
        printf("Enter any name ");
        gets(n[i]);
    }
    /* display */
    for(i=0;i<5;i++)
    {
        printf("%s\n",n[i]);
    }
    getch();
    return(0);
}
/* Output */

Enter any name Amit
Enter any name Sumit
Enter any name Kapil
Enter any name Mohan
Enter any name Madan
Amit
Sumit
Kapil
Mohan
Madan

C Language Programming Tutorial

C Language Tutorial Home     Introduction to C Language     Tokens     If Condition      goto statement and Labelname     Switch Statements     For loop     While Loop     Do while loop     break and continue     Functions     Recursion     Inbuild Functions     Storage Classes     Preprocessor     Arrays     Pointers     Structures and Unions     File Handling     Projects