平方根和数组?

unser 2003-04-09 03:35:40
//求该数的平方和平方根
#include <stdio.h>
#include <math.h>
void main()
{
int a;
int b;
printf("Enter the number:\n");
scanf("%d",&a);
printf("The square of the number: %d\n",a*a);
b=(int)sqrt(a);
printf("The square root of the number: %d\n",b);
}
//如何使该数值的平方根输出为"有小数点的数"(如:3.221)


当我们要输入一条信息的时间,如果用数组定义的话,用printf语句显示的内容也只是空格之前的字符。
比如我输入为“this is my home!”,那么只显示"this".
这个问题应该怎么解决?
...全文
67 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
andyfr1210 2003-04-09
  • 打赏
  • 举报
回复
up
ssson 2003-04-09
  • 打赏
  • 举报
回复
%d 改成 %f
wyqiang 2003-04-09
  • 打赏
  • 举报
回复
100
有我的吧
%d 改成 %f
b=(int)sqrt(a);
double a;
改为b=(double)squrt(a);
freeleo 2003-04-09
  • 打赏
  • 举报
回复
scanf在空格和回车的时侯认为输入结束,gets(),puts()好像是一行的输入输出,
printf("%s",....)输出字符串应该没有问题
woxihuanbohe 2003-04-09
  • 打赏
  • 举报
回复
#include<iomanip.h>输入输出流控制
具体怎么用请参考书籍
maurice1983 2003-04-09
  • 打赏
  • 举报
回复
在c中:
#include <stdio.h>

int main()
{
char a[255] = "this is my home";
puts(a);

return 1;
}
在c++中:
#include <iostream>

using namespace std;

int main()
{
char a[255] = "this is my home";
std::cout << a;

return 1;
}
zhaoao 2003-04-09
  • 打赏
  • 举报
回复
1: %d 改成 %f

2:不要用scanf接受字符串,用gets
unser 2003-04-09
  • 打赏
  • 举报
回复
当我们要输入一条信息的时间,如果用数组定义的话,用printf语句显示的内容也只是空格之前的字符。
比如我输入为“this is my home!”,那么只显示"this".
这个问题应该怎么解决?
zPerry 2003-04-09
  • 打赏
  • 举报
回复
int 可以显示小数点吗?用 double 算了。
TopCat 2003-04-09
  • 打赏
  • 举报
回复
1: %d 改成 %f

2:不要用scanf接受字符串,用gets

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧