# 实验2

#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("2023831%04d\n", number);
}
return 0;
}


Line 15的作用是 生成一个1~65之间的随机数

#include <stdio.h>

int main() {
char c;
while ((c = getchar()) != EOF) {
getchar();
if (c == 'r') {
printf("stop!\n");
}
else if (c == 'g') {
printf("go go go\n");
}
else if (c == 'y') {
printf("wait a minute\n");
}
else {
printf("something must be wrong...\n");
}
}
return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {
int lucky_day;
int guess;
int cnt;

srand(time(0));
lucky_day = rand() % 31 + 1;
printf("猜猜2024年5月哪一天会是你的lucky_day\n");
printf("开始喽,你有三次机会,猜吧(1~31):");

for (cnt = 0; cnt < 3; ++cnt) {
scanf_s("%d", &guess);

if (guess == lucky_day) {
printf("哇,猜中了：-)\n");
return 0;
}
else if (guess < lucky_day) {
printf("你猜的日期早了,你的lucky_day还没到呢\n");
}
else {
printf("你猜的日期晚了,你的lucky_day在前面哦\n");
}
if (cnt < 2)
{
printf("\n再猜(1~31):");
}

}
if (cnt == 3) {
printf("\n\n次数用完了,偷偷告诉你,5月你的lucky_day是%d号\n", lucky_day);
}
return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main() {
int n, a, j, i,k;
double s;

while (scanf_s("%d%d", &n, &a) != EOF) {
s = 0.0;
for (i = 1; i <= n; i++) {
k = 0;
for (j = 0; j < i; j++) {
k = k * 10 + a;
}
s += 1.0 * i / k;
}
printf("n=%d,a=%d,s=%1f\n\n", n, a, s);
}
return 0;
}


#include <stdio.h>

int main() {
int i, j;
for (i = 1; i <= 9; i++) {
for (j = 1; j <= i; j++) {
printf("%d*%d=%d\t", i, j, i * j);
}
printf("\n");
}
return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main() {
int n, i, m, j;
printf("input n:");
scanf_s("%d", &n);

for (i = 0; i < n; i++)
{
for (j = 0; j < i; j++)
{
printf("\t");
}
for (m=2*(n-i)-1;m>0;m--)
{
printf(" O \t");
}
printf("\n");

for (j = 0; j < i; j++)
{
printf("\t");
}
for (m=2*(n-i)-1;m>0;m--) {
printf("<H>\t");
}
printf("\n");

for (j = 0; j < i; j++)
{
printf("\t");
}
for (m = 2 * (n - i) - 1; m > 0; m--)
{
printf("I I\t");
}
printf("\n");
}
return 0;
}


posted @ 2024-04-10 20:32  程欣雨  阅读(9)  评论(0编辑  收藏  举报