啊哈磊_编程从这里起步

标题: 如何输入一个数字,求它的平方?需代码。 [打印本页]

作者: Sheldon    时间: 2015-2-4 15:39
标题: 如何输入一个数字,求它的平方?需代码。
例:输入5,输出25.
作者: 981013    时间: 2015-2-4 15:39
[mw_shl_code=c,true]#include <stdio.h>
#include <stdlib.h>
int main()
{
    double a;
    scanf("%lf",&a);
    printf("%g",a*a);
    system("pause");
    return 0;
}[/mw_shl_code]
作者: Sheldon    时间: 2015-2-6 12:05
981013 发表于 2015-2-4 15:39
[mw_shl_code=c,true]#include
#include
int main()

"double","%lf","%g"都是什么意思?
作者: 981013    时间: 2015-2-6 21:44
Sheldon 发表于 2015-2-6 12:05
"double","%lf","%g"都是什么意思?

double就是双精度浮点数
%lf——双精度浮点数的输入格式控制符
%g——双精度浮点数的输出格式控制符,当然用%lf输出也可,但%g的结果更“好看”
具体请自行百度“格式控制符”

作者: asdfghjklzxcvbn    时间: 2015-2-14 18:54
#include <stdio.h>
#include <stdlib.h>
int main()
{
    double a;
    scanf("%lf",&a);
    printf("%g",a*a);
    system("pause");
    return 0;
}
作者: 784056885    时间: 2015-2-16 12:06
01
02
03
04
05
06
07
08
09
10
#include <stdio.h>
#include <stdlib.h>
int main()
{
    double a;
    scanf("%lf",&a);
    printf("%g",a*a);
    system("pause");
    return 0;
}




欢迎光临 啊哈磊_编程从这里起步 (https://bbs.codeaha.com/) Powered by Discuz! X3.2