Advertisement
Mary_99

Name and Surname = ex.3.1

Nov 25th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. /*write a program reading names and surnames of 15 student, storing them in an array and printing on the screen as follows;:
  5. name and surname  or in a reserved order*/
  6.  
  7. { // program  shows writing ( reading) the data into (from) multidimensional array
  8.     char c;
  9.     char tab [15][2][20];
  10.     int n, i ;
  11.     do
  12.     {
  13.         printf("Enter students number(n<16):");
  14.         i = scanf("%d", &n);
  15.         fflush(stdin);//stdio.h -clearing the buffer
  16.  
  17.     }
  18.     while (i ==0);
  19.     system("cls");////stdio.h -clearing the screen
  20.     for ( i = 0; i <n; i ++)
  21.     {
  22.         printf("Enter name of %d student: ", i+1);
  23.         scanf("%19s", &tab[i][0]);
  24.         fflush(stdin);
  25.         printf("Enter surname of %d student: ", i+1);
  26.         scanf("%19s", &tab[i][1]);
  27.         fflush(stdin);
  28.         printf("\n");
  29.     }
  30.     printf("Printing firstly name, than suname? t\n");
  31.     fflush(stdin);
  32.     c = getchar();
  33.     printf("\n");
  34.     if(c == 't' || c == 'T')
  35.         for( i = 0; i <n; i ++)
  36.             printf("%d %s %s\n", i+1, tab[i][0],tab[i][1]);
  37.     else for (i = 0; i <n; i ++)
  38.             printf("%d %s %s\n", i+1, tab[i][1],tab[i][0]);
  39.     getchar();
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement