|
查看: 1132|回复: 9
|
C Language: data types [已解决]
[复制链接]
|
|
|
- Write a printf and scanf statement for each of the following:
- a. Print 200 with and without a sign.
- b. Print 1.234 in a 9-digit field with preceding zeros.
- c. Print 123.456789 in exponential notation with a sign(+ or -) and 3 digits of precision.
- d. Read characters into array s until the letter p is encountered
- e. Read a float value into variable num.
- */
- #include
- void main()
- {
- int a=200;
- unsigned int b=200;
- const double c=1.234;
- const double d=123.456789;
- char s[50];
- int count=0;
- float f;
- int i;
- printf("rint 200 with and without a sign:\n";
- printf("With a sign = %d\n",a);
- printf("Without a sign = %d\n",b);
- printf("\n";
- printf("rint 1.234 in a 9-digit field with preceding zeros: ";
- printf("%.9f\n",c);
- printf("\n";
- printf("rint 123.456789 in exponential notation with:\n";
- printf("a sign(+ or -) and 3 digits of precision:\n";
- printf("%.3Ef\n",d);
- printf("\n";
- printf("Read characters into array s until the letter p is encountered:\n";
- do
- {
- scanf("%c",&s[count]);
- count++;
- }while(s[count]!='p');
- printf("\n";
- printf("Read a float value into variable num:\n";
- scanf("%f",&f);
- i = (int)(f + 0.5f);
- printf("%d",i);
- }
复制代码 没有error
可是output卡在bold字那个部分了。。。
打了p也不会停
看不到问题。。。
[ 本帖最后由 蜡笔小烦 于 18-10-2008 03:33 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 15-10-2008 10:26 PM
|
显示全部楼层
printf("\n";
少了 )
第一眼看到這個 |
|
|
|
|
|
|
|
|
|
|
发表于 15-10-2008 11:01 PM
|
显示全部楼层
- do
- {
- scanf("%c",&s[count]);
- count++;
- }while(s[count-1] != 'p');
复制代码 index應該是count-1
s[count]還沒有被assign value |
|
|
|
|
|
|
|
|
|
|
发表于 15-10-2008 11:23 PM
|
显示全部楼层
scanf("%c",&s[count]);
s 在這條line會被改寫 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 16-10-2008 10:45 AM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 16-10-2008 10:45 AM
|
显示全部楼层
原帖由 零翼 于 15-10-2008 11:23 PM 发表 
scanf("%c",&s[count]);
s 在這條line會被改寫
啊???
不明
不好意思。。 |
|
|
|
|
|
|
|
|
|
|
发表于 16-10-2008 06:38 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 16-10-2008 06:48 PM
|
显示全部楼层
原帖由 cheng1986 于 16-10-2008 06:38 PM 发表 
現在這樣就對了
應該是問題有問題...
噢
是这样子
这一个部分
我不是很确定
是不是这样子做。。。
printf("rint 200 with and without a sign:\n";
printf("With a sign = %d\n",a);
printf("Without a sign = %d\n",b);
printf("\n";
[ 本帖最后由 蜡笔小烦 于 16-10-2008 06:57 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 17-10-2008 09:12 AM
|
显示全部楼层
print without sign
printf("%d", 200);
with sign
printf("%+d",200);
c. Print 123.456789 in exponential notation with a sign(+ or -) and 3 digits of precision.
printf("%+.3e", 123.456789);
[ 本帖最后由 onlylonly 于 17-10-2008 09:19 AM 编辑 ] |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 18-10-2008 03:10 PM
|
显示全部楼层
原帖由 onlylonly 于 17-10-2008 09:12 AM 发表 
print without sign
printf("%d", 200);
with sign
printf("%+d",200);
c. Print 123.456789 in exponential notation with a sign(+ or -) and 3 digits of precision.
printf("%+.3e", 123.456789);
...
原来是这样
谢谢 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|