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);
}
return 0;
}
点击查看代码
#include <stdio.h>
int main()
{
char colour;
printf("请输入交通信号灯的颜色:");
while ((colour = getchar()) != EOF)
{
switch (colour)
{
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");
}
getchar();
}
return 0;
}
点击查看代码
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main() {
int number, m, i;
srand(time(0));
printf("猜猜2024年5月哪一天会是你的lucky day");
number = rand() % 30 + 1;
printf("\n");
printf("开始喽,你有三次机会,猜吧(1~31):");
scanf_s("%d", &m);
for (i = 0; i < 2; ++i)
{
if (m > number)
{
printf("你猜的日期晚了,你的lucky day在前面哦\n再猜(1~31):");
scanf_s("%d", &m);
}
else if (m < number)
{
printf("你猜的日期早了,你的lucky day还没到呢\n再猜(1~31):");
scanf_s("%d", &m);
}
else
{
printf("哇,猜中了:-)");
break;
}
}
if (i == 2)
printf("次数用完啦。偷偷告诉你,5月你的lucky day是%d", number);
return 0;
}
点击查看代码
#include<stdio.h>
int main()
{
int n, a, i, up, down;
double s, ans;
ans = 0;
printf("请输入正整数n和a:");
while (scanf_s("%d %d", &n, &a) != EOF)
{
for (i = 1, s = 0, down = 0; i <= n; i++)
{
up = i;
down = down * 10 + a;
ans = up * 1.0 / down;
s = s + ans;
}
printf("n=%d,a=%d,s=%f", n, a, s);
printf("\n请输入正整数n和a:"); }
return 0;
}
点击查看代码
![](/i/l/?n=24&i=blog/3405472/202404/3405472-20240415140358685-888898226.png)
点击查看代码
#define _CRT_SECURE_NO_WARNINGS
#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");
}
system("pause");
return 0;
}