task1
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 5 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { int grade, number; int i; srand(time(0)); for(i=0;i<N;++i) { grade=rand()%4+2018; number=rand()%999+1; printf("%d8330%04d\n",grade,number); } return 0; }
1,随机生成一个小于4的数加2018
2,随机生成一个1到999之间的三位数
3,在2018届到2021届中随机抽取同学五位
task 2
printf("你有三次机会 猜吧(1~30):"); for(i=0;i<=4;i++) { scanf("%d",&guess); if(guess==lucky_day) { printf("猜中了"); break; } else { if(guess>lucky_day) {printf("日期晚了"); } if(guess<lucky_day) {printf("日期早了"); } } i+=1; if(i>3) { printf("你的机会用完了,偷偷告诉你你的lucky_day是%d",lucky_day); break; } printf("再猜:"); } return 0; }
task 3
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { char colour; while(scanf("%c",&colour)!=EOF) { printf("输入:"); scanf("%c",&colour); if(colour=='y') printf("wait a minute\n"); if(colour=='g') printf("go go go\n"); if(colour=='r') printf("stop\n"); if((colour!='y')&&(colour!='g')&&(colour!='r')) printf("something must be wrong...\n"); } return 0; }
task 4
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int n,a,b,i; double s,t,c; printf("please input:"); while(scanf("%d %d",&n,&a)!=EOF) { c=1.0,s=0; for(b=1;b<=n;b++) { c=0; for(i=0;i<b;i++){ c=c+pow(10,i)*a; } t=b/c; s=s+t; } printf("n=%d, a=%d, s=%lf",n,a,s); printf("\nplease input:"); } return 0; }
task 5
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int line,column,value; for(line=1;line<=9;line++) { for(column=1;column<=line;column++) { value=line*column; printf("%8d*%d=%2d",line,column,value); } printf("\n"); } return 0; }
task 6_1
#include <stdio.h> #include <stdlib.h> int main(int argc, char*argv[]) { int n,i; scanf("%d",&n); for(i=1;i<=n;i++) { printf(" O \n"); printf("<H>\n"); printf("I I\n");} return 0; }
task 6_2
#include <stdio.h> #include <stdlib.h> int main(int argc, char*argv[]) { int n,i; scanf("%d",&n); for(i=1;i<=n;i++) { printf(" O ");} printf("\n"); for(i=1;i<=n;i++) { printf(" <H>");} printf("\n"); //printf(" <H>"); for(i=1;i<=n;i++) { printf(" I I");} printf("\n"); //printf(" I I");} return 0; }
task 6_3
#include <stdio.h> #include <stdlib.h> int main(int argc, char*argv[]) { int n,i,j,blank; scanf("%d",&n); for(i=1;i<=n;i+=2)//换一列 { for(blank=0;blank<i;blank++) { printf(" ");} // for(j=1;j<=n+1-i;j++) { printf(" O ");} printf("\n"); for(blank=0;blank<i;blank++) { printf(" ");} for(j=1;j<=n+1-i;j++) { printf(" <H>");} printf("\n"); for(blank=0;blank<i;blank++) { printf(" ");} for(j=1;j<=n+1-i;j++) { printf(" I I");} printf("\n"); } return 0; }