add xunhuan3-4

This commit is contained in:
zibright 2025-05-12 15:12:59 +08:00
parent 21399519ab
commit 60d1a9d701
10 changed files with 94 additions and 4 deletions

BIN
Code/output/sunhuan3 Normal file

Binary file not shown.

BIN
Code/output/test Normal file

Binary file not shown.

Binary file not shown.

BIN
Code/output/xunhuan3 Normal file

Binary file not shown.

BIN
Code/output/xunhuan4 Normal file

Binary file not shown.

10
Code/test.c Normal file
View File

@ -0,0 +1,10 @@
#include<stdio.h>
int main()
{
return 0;
}

View File

@ -2,11 +2,12 @@
int main()
{
int x = 0,i = 0;
for(i = 1; i <= 100; i++)
int sum = 0,i = 1;
while(i <= 100)
{
x += i;
sum += i;
i++;
}
printf("%d\n", x);
printf("%d\n", sum);
return 0;
}

View File

@ -19,5 +19,19 @@ int main()
}
}
/*
while(1)
{
printf("请输入两个整数:\n");
scanf("%d %d", &x , &y);
if(x == y)
{
printf("%d = %d\nexit\n",x,y);
break;
}
x > y ? printf("%d更大\n", x) : printf("%d更大\n", y);
}*/
return 0;
}

27
Code/xunhuan3.c Normal file
View File

@ -0,0 +1,27 @@
#include <stdio.h>
int main()
{
int n,i,j;
for(j=0;j<5;j++)
{
printf("请输入第%d个数\n",j+1);
scanf("%d",&n);
if(n<2)
{
printf("%d不是素数\n",n);
continue;
}
for(i=2;i<n;i++)
if(n%i==0)
break;
if(i<n)
printf("%d不是素数\n",n);
else
printf("%d是素数\n",n);
}
return 0;
}

38
Code/xunhuan4.c Normal file
View File

@ -0,0 +1,38 @@
#include <stdio.h>
int main()
{
int n; //菱形的一半高度
int i, j;
printf("请输入菱形的高度:");
scanf("%d", &n);
//上半
for (i = 1; i <= n; i++)
{
for (j = i; j < n; j++)
{
printf(" ");
}
for (j = 1; j <= (2 * i - 1); j++)
{
printf("*");
}
printf("\n");
}
//下半
for (i = n - 1; i >= 1; i--)
{
for (j = n; j > i; j--)
{
printf(" ");
}
for (j = 1; j <= (2 * i - 1); j++)
{
printf("*");
}
printf("\n");
}
return 0;
}