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