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("2023833%04d\n",number);
}
return 0;
}
TASK 2
点击查看代码
#include <stdio.h>
#include <stdlib.h>
int main(){
char n;
while(scanf("%c",&n)!=EOF)
{
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……");break;
}
getchar();
}
return 0;
}
TASK 3
点击查看代码
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int luckyday,guess;
int n=0;
srand(time(0));
luckyday=rand()%31+1;
printf("猜猜2024年5月哪一天会是你的lucky day\n\n");
printf("开始喽,你有三次机会,猜吧(1~31):");
while(n<3)
{
scanf("%d",&guess);
if(guess==luckyday)
{
printf("哇,猜中了:-)\n");
}
else if(guess<luckyday)
{
printf("你猜的日期早了,你的lucky day还没到呢\n");
}
else
{
printf("你猜的日期晚了,你的lucky day在前面哦\n");
}
if(n<2)
{
printf("\n再猜(1~31):");
}
n++;
}
if(n==3)
{
printf("\n\n次数用完了,偷偷告诉你,5月你的lucky day是%d号\n",luckyday);
}
return 0;
}
TASK4
点击查看代码
#include <stdio.h>
#include<stdlib.h>
int main() {
int n, a, i, j, m=0;
double s = 0.0;
while (scanf("%d%d", &n, &a) != EOF) {
s = 0.0;
for (i = 1; i <= n; i++) {
m=0;
for (j = 0; j < i; j++) {
m = m * 10 + 1;
}
s += (double)i / (a * m);
}
printf("n = %d, a = %d, s = %lf\n\n", n, a, s);
}
system("pause");
return 0;
}
TASK5
点击查看代码
#include <stdio.h>
#include<stdlib.h>
int main() {
int i, j;
for (i = 1; i <= 9; i++)
{
for (j = 1; j <= i; j++)
{
printf("%d×%d =%2d\t", j, i, i * j);
}
printf("\n");
}
system("pause");
return 0;
}
TASK 6
点击查看代码
#include <stdio.h>
#include <stdlib.h>
int main() {
int n, i, k, j;
printf("input n:");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
for (j = 0; j < i; j++)
{
printf("\t");
}
for (k = 2 * (n-i) - 1; k>0; k--)
{
printf(" O \t");
}
printf("\n");
for (j = 0; j < i; j++)
{
printf("\t");
}
for (k = 2 * (n-i) - 1; k>0; k--) {
printf("<H>\t");
}
printf("\n");
for (j = 0; j < i; j++)
{
printf("\t");
}
for (k = 2 * (n - i) - 1; k > 0; k--)
{
printf("I I\t");
}
printf("\n");
}
return 0;
}