task 1
点击查看代码
#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()%65 + 1;
printf("20238331%04d\n", number);
}
system("pause:");
return 0;
}
task 2
点击查看代码
#include <stdio.h>
#include <stdlib.h>
int main(){
char n;
printf("输入一个颜色\n");
while(n=getchar()!=EOF){
if(n=='r')
printf("stop!\n");
else if (n=='g')
printf("go go go\n");
else if (n=='y')
printf("wait a minute\n");
else
printf("something must be wrong\n");
getchar();
}
system("pause:");
return 0;
}
task 3
点击查看代码
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int number;
int a ,b ,c , i ,n;
n = 3;
srand( time(0) );
number = rand()%31 + 1;
for(i=0;i<n;i++)
{scanf("%d",&a);
if(number==a)
{printf("猜中了\n");break;}
else if(number<a)
printf("大了\n");
else if(number>a)
printf("小了\n");
}
printf("你的幸运day是:%d\n",number);
system("pause:");
return 0;
}
点击查看代码
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int a, n ,i ;
double sum = 0,c=0;
while(scanf("%d%d",&a,&n)!=EOF)
{for(i=1;i<=n;i++)
{c = 10 * c + (double)a;
sum += i / c;
}
printf("sum=%lf\n", sum);
}
system("pause:");
return 0;
}
点击查看代码
#include <stdio.h>
#include<stdlib.h>
int main()
{
int c, l, n;
for (c = 1; c <= 9; c++)
{
for (l = 1; l <= c; l++)
{
n = c * l;
printf("%dx%d =%4d ", l, c, n);
if (l == c)
printf("\n");
}
}
system("pause:");
return 0;
}
点击查看代码
#include <stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
int n,i,j;
scanf("%d", &n);
for (i=n;i>0;i--)
{
for (j = 0; j < n - i; j++)
{
printf(" \t");
}
for (j = 0; j < (2 * i - 1); j++)
{
printf(" O \t");
}
printf("\n");
for (j = 0; j < n - i; j++)
{
printf(" \t");
}
for (j = 0; j < (2 * i - 1); j++)
{
printf("<H>\t");
}
printf("\n");
for (j = 0; j < n - i; j++)
{
printf(" \t");
}
for (j = 0; j < (2 * i - 1); j++)
{
printf("I I\t");
}
printf("\n");
}
system("pause:");
return 0;
}