Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1597360
  • 博文数量: 101
  • 博客积分: 2465
  • 博客等级: 中尉
  • 技术积分: 2126
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-09 15:39
个人简介

https://minminmsn.com/

文章分类

全部博文(101)

文章存档

2018年(2)

2017年(2)

2016年(11)

2015年(14)

2014年(9)

2013年(16)

2012年(47)

分类: C/C++

2013-03-17 22:08:26

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();
}

阅读(2039) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~