实现输入错误后重新输入

通过输入指定的行数和列数打印出二维数组对应的任一行任一列的值:

 1 #include <stdio.h>
 2 
 3 void main()
 4 {
 5     int a[3][4] = {{1, 2, 3, 4},{5, 6, 7, 8},{9, 10, 11, 12}};
 6     int i, j;
 7     int (*p)[4];
 8     printf("i = ");
 9     scanf("%d", &i);
10     while(i>2 || i<0)
11     {
12         printf("i = ");
13         scanf("%d", &i);
14     }
15     printf("j = ");
16     scanf("%d", &j);
17     while(j>3 || i<0)
18     {
19         printf("j = ");
20         scanf("%d", &j);
21     }
22     p = a;
23     printf("a[%d][%d] = %d\n", i, j, *(*(p+i)+j));
24 }

 

posted on 2018-07-22 16:41  WKQcoding  阅读(180)  评论(0编辑  收藏  举报