第一道:#include <stdio.h>
int main(void)
{
int i , j ;
i = 0 ;
while(i < 9) {
j = 0 ;
while(j < i + 1) {
if(j) printf(",") ;
printf("%2d" , i + 1) ;
j ++ ;
}
printf("\n") ;
i ++ ;
}
return 0 ;
}
编译运行实况:C:\Bin>g++ -o k1 k1.c
C:\Bin>k1
1
2, 2
3, 3, 3
4, 4, 4, 4
5, 5, 5, 5, 5
6, 6, 6, 6, 6, 6
7, 7, 7, 7, 7, 7, 7
8, 8, 8, 8, 8, 8, 8, 8
9, 9, 9, 9, 9, 9, 9, 9, 9
C:\Bin>
第二道:#include <stdio.h>
int main(void)
{
int i , j ;
i = 0 ;
while(i < 20) {
j = 0 ;
while(j < i + 1) {
if(j) printf(",") ;
printf("%2d" , j + 1) ;
j ++ ;
}
printf("\n") ;
i ++ ;
}
return 0 ;
}
编译运行实况:C:\Bin>g++ -o k2 k2.c
C:\Bin>k2
1
1, 2
1, 2, 3
1, 2, 3, 4
1, 2, 3, 4, 5
1, 2, 3, 4, 5, 6
1, 2, 3, 4, 5, 6, 7
1, 2, 3, 4, 5, 6, 7, 8
1, 2, 3, 4, 5, 6, 7, 8, 9
1, 2, 3, 4, 5, 6, 7, 8, 9,10
1, 2, 3, 4, 5, 6, 7, 8, 9,10,11
1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12
1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13
1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14
1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15
1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16
1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17
1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18
1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19
1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20
C:\Bin>
|