1,鸡兔同笼
#include
main()
{
int total,feet,rabbit,chick;
printf("input total:");
scanf("%d",&total);
printf("input feet:");
scanf("%d",&feet);
rabbit=(feet-2*total)/2;
chick=2*total-feet/2;
printf("total=%d,feet=%d,rabbit=%d,chick=%d",total,feet,rabbit,chick);
getch();
}
2,替换排序
#include
main()
{
/*任给三个数字a,b,c,比较大小按照从大到小顺序输出
分析:使用判断交换法 a
printf("please input a,b,c:");
scanf("%d%d%d",&a,&b,&c);
if(a
{t=a;a=b;b=t;}
if(a
{t=a;a=c;c=t;}
if(b
{t=b;b=c;c=t;}
printf("form min to max is:%d<%d<%d",c,b,a);
getch();
}
3,除余运算
#include
main()
{
long int num,a,b,c,d,e,sum;
printf("please input a five bit integer:");
scanf("%ld",&num);
a=num%10;
num=num/10;
b=num%10;
num=num/10;
c=num%10;
num=num/10;
d=num%10;
num=num/10;
e=num%10;
sum=a+b+c+d+e;
printf("The sum of all the numbers is %ld.",sum);
getch();
}
4,三个数取最大
#include
main()
{
int a,b,c;
printf("please input a,b,c:");
scanf("%d%d%d",&a,&b,&c);
if(a>b&&a>c)
printf("the max is %d",a);
else
if(b>c)
printf("the max is %d",b);
else
printf("the max is %d",c);
getch();
}
5,判断三角形
#include
main()
{
int a,b,c;
printf("please input a,b,c:");
scanf("%d%d%d",&a,&b,&c);
/*first judge triangle*/
if(a+b>c&&a+c>b&&b+c>a)
/*second judge equilateral triangle*/
if(a==b&&a==c)
printf("a,b,c can form a equilateral triangle.");
else
/*third judge isosceles right-angled triangle*/
if((a==b||b==c||a==c)&&(a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a))
printf("a,b,c can form a isosceles right-angled triangle.");
else
/*fourth judge isosceles triangle*/
if(a==b||b==c||a==c)
printf("a,b,c can form a isosceles triangle.");
else
/*fifth judge right-angled triangle*/
if(a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a)
printf("a,b,c can form a right-angled triangle.");
/*last trangle*/
else
printf("a,b,c can form a triangle.");
/*otherwise not triangle*/
else
printf("a,b,c can not form a triangle.");
getch();
}
阅读(2099) | 评论(0) | 转发(0) |