//输入10个数并输出最大(自己第一次编的版本)
#include <stdio.h>
int main(void)
{
int i=1,time=1,number_1,number_2,number_more,bigger;
int max(int x, int y);
printf("Type number %d: ",time);
++time;
scanf("%d",&number_1);
printf("Type number %d: ",time);
++time;
scanf("%d",&number_2);
bigger=max(number_1,number_2);
for (i;i<=8;i++)
{
printf("Type number %d: ",time);
++time;
scanf("%d",&number_more);
bigger=max(bigger,number_more);
}
printf("The biggest number is: %d",bigger);
//system("pause");
return 0;
}
int max(int x,int y) //声明max函数
{
int big;
if(x>y)
big=x;
else
big=y;
return(big);
}
//输入10个数并输出最大(经过高人指导后的版本)
#include <stdio.h>
int main(void)
{
int i,time=1,number,bigger;
for(i=0;i<10;i++)
{
printf("Type number %d: ",time);
time++;
scanf("%d",&number);
if(i==0)
bigger=number;
if(number>bigger)
bigger=number;
}
printf("The biggest number is %d",bigger);
//system("pause");
return 0;
}
//1+2+3+...+100
#include <stdio.h>
int main(void)
{
int sum=0,i=1;
for(i;i<=100;i++)
{
sum=sum+i;
}
printf("Sum=%d",sum);
//system("pause");
return 0;
}
//求100到200之间的质数
#include <stdio.h>
int main(void)
{
int number;
_Bool isPrime;
for(number=100;number<201;number++)
{
isPrime=prime(number);
if(isPrime!=0)
printf("%d\t",number);
}
//system("pause");
return 0;
}
int prime(int _p) //定义prime函数,返回布尔值
{
int _i;
for(_i=2;_i<_p;_i++)
{
if(_p%_i==0)
return 0;
else
return 1;
}
}
评论