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() % 65 + 1;
printf("20238331%04d\n", number);
}
return 0;
}
Line15作用为生成一个1-65的随机数
程序功能为随机生成五个对应班级的学生学号
task2
#include<stdio.h>;
#include<stdlib.h>;
int main(){
char n;
int x;
while(scanf("%d",&x)!=EOF)
{
scanf("%c",&n);
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");
system("pause");
}
return 0;
}
task3
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
int n,x,y= 0;
srand(time(0));
n= rand() % 31 + 1;
printf("猜猜2024年5月哪一天会是你的lucky day\n\n");
printf("开始喽,你有三次机会,猜吧(1~31):");
while (y < 3)
{
scanf("%d", &x);
printf("\n");
if (x == n)
{
printf("哇,猜中了:-)\n");
return 0;
}
else if (x < n)
{
printf("你猜的日期早了,你的lucky day还没到呢\n");
}
else
{
printf("你猜的日期晚了,你的lucky day在前面哦\n");
}
if (y < 2)
{
printf("\n再猜(1~31):");
}
y++;
}
if (y == 3)
{
printf("\n\n次数用完了,偷偷告诉你,5月你的lucky day是%d号\n", n);
}
system("pause");
return 0;
}
task4
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main(){
int n,a,i,j,m=0;
double sum=0.0;
while (scanf("%d%d",&n,&a)!=EOF){
sum=0.0;
for (i=1;i<=n;i++){
m=0;
for(j=0;j<i;j++){
m=m*10+1;
}
sum+=(double)i/(a*m);
}
printf("n=%d,a=%d,sum=%lf\n\n",n,a,sum);
}
system("pause");
return 0;
}
task5
#include<stdio.h>
int main()
{
for (int i = 1; i <= 9; i++){
for (int j = 1; j <= i; j++){
printf("%2d*%2d=%2d ", j, i, i * j);
}
printf("\n");
}
return 0;
}
task.6
#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;
}
标签:main,return,int,scanf,编程,C语言,printf,include,分支
From: https://www.cnblogs.com/Potyomkin/p/18135931