#include <stdio.h>
#include <math.h>
void main()
{
long i,n,temp;
printf("请输入n\n");
scanf("%d",&n);
for ( i = 1 ; i <= n ; i++ )
{
temp = pow(i,2);
printf("%d的平方 = %d\n",i,temp);
temp = pow(i,3);
printf("%d的立方 = %d\n",i,temp);
}
}

总结:加了个#include <stdio.h> 的头文件,使用了pow(x,y)函数。
本文介绍了一个简单的C语言程序,该程序利用标准库中的pow函数来计算并打印从1到用户指定数字n的所有整数的平方和立方。通过这个例子,读者可以了解如何在C语言中引入和使用数学库。
540

被折叠的 条评论
为什么被折叠?



