zoukankan      html  css  js  c++  java
  • C语言典型编程1

    关于C的一些小而精的编程,适合希望提升编程能力的初学者学习:关键编程也就几句,但思维可以迁移到其他编程语言。同一问题,算法多种

    //阶乘运算(有多种编写方式,编程需要看懂,更要打出来
    #include<stdio.h>
    main()
    {
        int x;
        float y=1;
        int i=2;
        scanf("%d",&x);
        while(x<0)
        {
            printf("input again:");
            scanf("%d",&x);
        }
        if(x==0||x==1)
        {
            printf("x!阶乘为%f",y);
            return 0;
        }
        while(i<=x)
        {
            y=y*i;
            i++;
        }
        printf("%d!=%f",x,y);
    }

    //3数降序排序
    #include<stdio.h>
    main()
    {
        int a,b,c,t;
        printf("input a,b,c,");
        scanf("%d%d%d",&a,&b,&c);
        if (a<b)
        {
            t=a;
            a=b;
            b=t;
        }
        if(a<c)
            {t=a;
        a=c;
        c=t;
        }
        if(b<c)
        {
            t=b;
            b=c;
            c=t;
        }
        printf("a=%d,b=%d,c=%d",a,b,c);
    }

    备注:暂时用比较基础的方法来写,循序渐进学习高级编程。如果看官能发挥主观能动性编写更好的,这更比程序重要。

  • 相关阅读:
    leetcode题库
    递归的存储以及执行顺序
    linux与开发板串口通信
    opencv基础到进阶(2)
    opencv基础到进阶(1)
    js的搜索遍历精讲
    js闭包深度讲解
    js使用for in遍历时的细节问题
    分分钟解决正则表达式
    css3中的新特性经典应用
  • 原文地址:https://www.cnblogs.com/llj9527/p/10738918.html
Copyright © 2011-2022 走看看