task.2
#include <stdio.h> int main() { char n; while(scanf("%c", &n)!=EOF) { getchar(); switch(n){ case'r':printf("stop!\n");break; case'g':printf("go go go\n");break; case'y':printf("wait a minute\n");break; default:printf("something must be wrong\n");break; } } return 0; }
task.3
include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int n, i, day, c; day = rand()%30 + 1; c = 0; printf("猜猜2023年11月那天是你的lucky day\n"); printf("开始喽,你有三次机会,猜吧\n"); for(i = 1; i <= 3; ++i) { scanf("%d", &n); if(n < day) { printf("你猜的日期早了,你的lucky day还没到呢\n"); c++; if(c<3) printf("再猜\n");} else if(n > day){printf("你的日期晚了,你的lucky day已经过期\n"); c++; if(c<3)printf("再猜\n");} else{printf("哇,猜中了\n");} break; } return 0; }
task.4
include <stdio.h> #include <math.h> int main() { int n,i,a; double s,down; while (scanf("%d%d",&n,&a)!=EOF) { s=0; down=a; for (i=1;i<=n;i++) { s+=i/down; down=down*10+a; } printf("n=%d a=%d s=%lf\n",n,a,s); } return 0; }
task.5
#include <stdio.h> int main() { int i, j; for(i = 1;i<=9;i++) { for(j = 1;j<=i;j++) { printf("%d*%d = %d",i, j, i*j);} if(i!=j) printf("\n"); } return 0; }
task.6
int main() { int n, i, j, m; scanf("%d", &n); for(i=n;i>=1;i--){ for(m=1;m<=(n-1);m++) { printf(" "); } for(j=1;j<=(2*i-1);j++) { printf(" O "); printf(" "); } printf("\n"); for (m=1;m<=(n-1);m++) { printf(" "); } for(j=1;j<=(2*i-1);j++) { printf("<H>"); printf(" "); } printf("\n"); for(m=1;m<=(n-i);m++) { printf(" "); } for(j=1;j<=(2*i-1);j++) { printf(" "); printf("I I"); } printf("\n"); } return 0; }
标签:include,int,break,实验,printf,main,day From: https://www.cnblogs.com/dbft/p/17775661.html