task1
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 5 int main() { int number; int i; srand( time(0) ); for(i = 0; i < N; ++i) { number = rand()%500 + 1; printf("20228329%04d\n", number); } return 0; } 1,生成1-500的随机数 2.生成随机
task2
#include<stdio.h> #include<stdlib.h> #include<time.h> #define N 3 int main() { int number; int i,x; srand( time(0) ); number=rand()%30+1; printf("猜猜2022年11月哪一天会是你的lucky day\n"); printf("开始喽,你有三次机会,猜吧(1~30):"); for(i=0;i<N;i++) { scanf("%d",&x); if(number<x){ printf("你猜的日期晚了,你的lucky day已经过啦\n"); printf("再猜(1~30):"); } else if(number>x){ printf("你猜的日期早啦,你的lucky还没到呢\n"); printf("再猜(1~30):"); } else if(number=x){ printf("哇,猜中了:-)"); } } printf("次数用完啦,告诉你:11月,你的lucky day是%02d号",number); return 0; }
task3
#include<stdio.h> int main() { char x; while(scanf("%c",&x)!=EOF) { getchar(); if(x=='r') { printf("stop!\n"); } else if(x=='g'){ printf("go go go\n"); } else if(x=='y'){ printf("wait a minute\n"); } else{ printf("something must be wrong\n"); } } return 0; }
task4
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int n,a,b,i; double s; while(scanf("%d%d",&n,&a)!=EOF) { s=0;b=0; for(i=1;i<=n;i++){ b=b*10+a; s=s+(double)i/b; } printf("n=%d,a=%d,s=%lf",n,a,s); printf("\n"); } return 0; }
task5
#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++) printf("%d*%d=%3d\t",column,line,column*line); printf("\n"); } return 0; }
task6
#include<stdio.h> int main() { int n = 0; scanf("%d",&n); for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { printf("\t"); } printf(" o "); for (int j = 0; j < (n - 1 - i) * 2; j++) { printf("\t"); printf(" o "); } printf("\n"); for (int j = 0; j < i; j++) { printf("\t"); } printf("<H>"); for (int j = 0; j < (n - 1 - i) * 2; j++) { printf("\t"); printf("<H>"); } printf("\n"); for (int j = 0; j < i; j++) { printf("\t"); } printf("I I"); for (int j = 0; j < (n - 1 - i) * 2; j++) { printf("\t"); printf("I I"); } printf("\n"); } return 0; } n行自上而下每行2i-1个图形;
标签:main,int,number,++,实验,printf,include From: https://www.cnblogs.com/pansiqi/p/16811308.html