编写一个函数square()对一个整数返回它的平方数 用c语言编写~

如题所述

代码如下:

#include <stdio.h>

int square(int a){

return a*a;

}

int main(void){

int a;

scanf("%d",&a);

printf("输入的数为%d\n",a);

printf("平方数为%d\n",square(a));

return 0;

} 。

代码运行结果:                                                                                                                        

扩展资料

C语言还提供了内置的库函数来求一个整数的平方数,就是内置math.h文件中含有乘方(包括开方)的库函数,编写程序导入Math.h文件就行,表示为:pow(x,y),其中x和y都是双精度浮点(double)型,x是底数,y是指数(如果是小数即为开方)。

参考资料:百度百科-C语言

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-12-20
#include <stdio.h>
int square (int x)
{
return x*x;
}
void mian()
{
int p;
int d;
printf("请输入一个整数:")
scanf("%d",&p);
d=square(p);
printf("%d\n",d);
}本回答被网友采纳
第2个回答  2015-12-04
int square(int x){
return x*x;
}
第3个回答  2015-12-04
int square(int N){
return N*N;
}追问

本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网