Presentation is loading. Please wait.

Presentation is loading. Please wait.

Do.For.While.正三角.倒正三角.倒九九乘法表

Similar presentations


Presentation on theme: "Do.For.While.正三角.倒正三角.倒九九乘法表"— Presentation transcript:

1 Do.For.While.正三角.倒正三角.倒九九乘法表

2 Do #include <stdio.h> #include <stdlib.h> int main(void) {
int no; int i = 1 ; int sum = 0 ; printf("請輸入整數a:"); scanf("%d",&no); do{ sum += i; i++; }while (i<=no); printf("1加到到整數a的總和:%d\n" ,sum); system("pause"); return(0);

3 For #include <stdio.h> #include <stdlib.h> int main(void)
{ int no,i; int sum=0; printf("請輸入整數a:"); scanf("%d",&no); for (i=1 ; i<=no ; i++) sum += i; printf("1加到整數a的總和:%d" ,sum); putchar('\n'); system("pause"); return(0); }

4 While #include <stdio.h> #include <stdlib.h>
int main(void) { int no,i; int sum = 0 ; printf("請輸入整數a:"); scanf("%d",&no); i=0; while(i<=no) {sum += i; i++;} printf("1加到到整數a的總和:%d" ,sum); putchar('\n'); system("pause"); return(0); }

5 正三角形 #include <stdio.h> #include <stdlib.h> int main(void)
{ int i , j , ln ; printf("金字塔型共幾列:") ; scanf("%d",&ln); for ( i = 1 ; i <= ln ; i++) { for ( j = 1 ; j <= ln-i ; j++) putchar(' '); for ( j = 1 ; j <= i*2-1 ; j++) putchar('*'); putchar('\n'); } system("pause"); return(0);

6 倒三角形 #include <stdio.h> #include <stdlib.h> int main(void)
{ int i , j , ln ; printf("金字塔型共幾列:") ; scanf("%d",&ln); for ( i = ln ; i >= 1 ; i--) { for ( j = ln-i ; j >= 1 ; j--) putchar(' '); for ( j = i*2-1 ; j >= 1 ; j--) putchar('*'); putchar('\n'); } system("pause"); return(0);

7 倒九九乘法表 #include <stdio.h> #include <stdlib.h>
int main(void) { int i , j; for (i = 9 ; i >= 1 ; i--){ for (j = 9 ; j>= 1 ; j--) printf("%3d", i * j); putchar('\n'); } system("pause"); return(0);


Download ppt "Do.For.While.正三角.倒正三角.倒九九乘法表"

Similar presentations


Ads by Google