zoukankan      html  css  js  c++  java
  • C语言函数练习1

    1.求自然数1~10的平方根和立方数
    #include <stdio.h>
    #include <math.h>

    int main()
    {
     int x=1;
     double squareroot, power;

     while(x<=10)
     {
      squareroot=sqrt(x);
      power=pow(x, 3);

      printf("%d的平方根是:%.2lf\n%d的立方是:%.2lf\n", x, squareroot, x, power);
      x++;
     }


     return 0;
    }


    2.内置函数floor()和ceil()的用法
    #include <stdio.h>
    #include <math.h>

    int main()
    {
     printf("==========floor()==========\n");
     printf("floor(99.1)=%f\n", floor(99.1));
     printf("floor(-99.1)=%f\n", floor(-99.1));
     printf("floor(99.9)=%f\n", floor(99.9));
     printf("floor(-99.9)=%f\n", floor(-99.9));

     printf("==========ceil()==========\n");
     printf("ceil(99.1)=%f\n", ceil(99.1));
     printf("ceil(-99.1)=%f\n", ceil(-99.1));
     printf("ceil(99.9)=%f\n", ceil(99.9));
     printf("ceil(-99.9)=%f\n", ceil(-99.9));


     return 0;
    }


    3.内置函数toupper()和tolower()的用法
    #include <stdio.h>
    #include <ctype.h>

    int main()
    {
     char msg1, msg2, to_upper, to_lower;
     
     printf("请输入一个小写字母:");
     msg1 = getchar();
     to_upper=toupper(msg1);
     printf("%c转换为大写字母是:%c\n", msg1, to_upper);

     fflush(stdin);
     printf("请输入一个大写字母:");
     msg2 = getchar();
     to_lower=tolower(msg1);
     printf("%c转换为小写字母是:%c\n", msg2, to_lower);

     return 0;
    }


    4.内置函数rand()的用法
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>

    int main()
    {
     int i;
     printf("产生10个从0~99之间的随机数序列:\n");

     for(i=0; i<10; i++)
      printf("%d\t", rand()%10);
     printf("\n");
     return 0;
    }

  • 相关阅读:
    寄存器详解
    Sleep(0)的妙用
    源码分析之Dictionary笔记
    ASP.NET Core框架的本质
    Dictionary实现(收藏的)
    微软的判断一个数是不是质数的算法
    C#性能优化:延迟初始化Lazy
    C#3 分部方法,简单标记一下
    单例下并发的情况下访问私有变量的一个典型问题
    BeforeFieldInit的小叙
  • 原文地址:https://www.cnblogs.com/storys/p/2910335.html
Copyright © 2011-2022 走看看