Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions practices/c/level1/some of lvl 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#include<stdio.h>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件名后缀应该是.c

int main()
{
int a,i,b;
b=0;
printf("请输入一个数:");
scanf("%d",&a);
for(i=2;i<a;i++)
{

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多余的空行

if(a%i!=0)
b++;
}
if(b==a-2)
printf("a为素数");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

缩进+大括号

else
printf("a不为素数");
}



#include<stdio.h>
int main()
{
int life,tn,qn,ds,son;
printf("年龄可能为:");
for(life=1;life++;life<=100)
{
tn=life/6;
qn=life/12;
ds=life/7;
son=life/2;
if(life==tn+qn+ds+5+son+4&&life%84==0)
printf("%d",life);
}
}



#include<stdio.h>
int main()
{
int shuixianhua,bai,shi,ge;
printf("水仙花数有:");
for(shuixianhua=100;shuixianhua<1000;shuixianhua++)
{
bai=shuixianhua/100;
shi=(shuixianhua-100*bai)/10;
ge=shuixianhua%10;
if(shuixianhua==ge*ge*ge+shi*shi*shi+bai*bai*bai)
printf("%d\t",shuixianhua);
}
}



#include<stdio.h>
int main()
{
int a,b,c;
printf("2到1000素数有:2\t");
for(a=3;a<=1000;a++)
{
c=0;
for(b=2;b<a;b++)
{
if(a%b!=0)
c++;
}
if(c==a-2)
printf("%d\t",a);
}
}



#include<stdio.h>
int sushu(int a)
{
int b, c=0;
for(b=2;b<a;b++)
{
if(a%b!=0)
c++;
}
if(c==a-2)
return 1;
else
return 0;
}

int main()
{
int i,j;
for(i=4;i<=100;i+=2)
{
for(j=2;j<=i/2;j++)
{
if(sushu(j)&&sushu(i-j))
printf("%d=%d+%d\t",i,j,i-j);
}
}
return 0;
}