初学者#1 [英] Beginner excersice #1

查看:93
本文介绍了初学者#1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我根据问题核心地做了以下计划吗?


问题:


/ * 1:你刚刚受雇由MacroMuscle,Inc。提供

(硬体软件)。该公司正在进入欧洲

市场,并希望将一英寸转换为bb厘米(1英寸= 2.54厘米)的程序。该公司希望设置

程序,以便提示用户输入一英寸

的值。你的任务是定义程序目标和

来设计程序(编程过程的第1步和第2步)。

* /


解决方案:


#include< stdio.h>


#define centmeter 2.54

int main(无效)

{

int inches_to_input;

float inches_to_output;

printf(" please enter a a英寸\ n");

scanf("%d"& inches_to_input);

inches_to_output = inches_to_input * centmeter;

printf(转换后的英寸为%f \ n,inch_to_output);

返回0;

}

Am I did the following program corectly according to the question?

Question:

/* 1:You have just been employed by MacroMuscle, Inc.
(Software for Hard Bodies). The company is entering the European
market and wants a program that converts inches to
centimeters (1 inch = 2.54 cm). The company wants the
program set up so that it prompts the user to enter an inch
value. Your assignment is to define the program objectives and
to design the program (steps 1 and 2 of the programming process).
*/

solution:

#include<stdio.h>

#define centmeter 2.54
int main(void)
{
int inches_to_input;
float inches_to_output;
printf("please enter a inches\n");
scanf("%d",&inches_to_input);
inches_to_output = inches_to_input * centmeter;
printf("inches converted is %f\n",inches_to_output);
return 0;
}

推荐答案

我认为你的程序是正确的,除了int类型的inches_to_input。

为什么你不设置inches_to_input的类型浮动?
I think your program is correct except the int type of inches_to_input.
Why don''t you set the type of inches_to_input to float?


Kies Lee写道:
Kies Lee wrote:
我认为你的程序是正确的,除了int类型in ches_to_input。
为什么不将inches_to_input的类型设置为float?
I think your program is correct except the int type of inches_to_input.
Why don''t you set the type of inches_to_input to float?




请在回复时提供上下文,不能保证其他人

已经(或将要)查看您要回复的帖子。请参阅
http://cfaj.freeshell.org/google/ 有关如何提供正确的

上下文和其他有用信息的详细信息。

您可能还会发现此URL有用 http://clc-wiki.net/wiki/Intro_to_clc

-

Flash Gordon

生活在有趣的时代。

虽然我的电子邮件地址说垃圾邮件,但它是真实的,我读了它。



Please provide context when replying, there is no guarantee that others
have (or ever will) see the post you are replying to. See
http://cfaj.freeshell.org/google/ for details on how to provide proper
context and other useful information.
You may also find this URL useful http://clc-wiki.net/wiki/Intro_to_clc
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.

C_beginner写道:
C_beginner wrote:
我是否根据问题核心地执行了以下程序?


在我看来它应该基本上可以工作,虽然你应该考虑一些

问题和风格问题。

问题:

/ * 1:您刚刚受雇于MacroMuscle,Inc。
(硬体软件)。该公司正在进入欧洲市场,并希望将一英寸转换为厘米(1英寸= 2.54厘米)的程序。该公司希望设置
程序,以便提示用户输入一英寸值。您的任务是定义程序目标和设计程序(编程过程的第1步和第2步)。
* /

解决方案:

#include< stdio.h>


人们可以更容易地阅读额外的空间。


#include< stdio.h>

#define centmeter 2.54
int main(无效)
{
int inches_to_input;


为什么要使用int?人们常常处理小数英寸。

显然,如果你改变它,你将不得不改变scanf格式

说明符。

float inches_to_output;


为什么要使用浮点数而不是双数?大多数时候,当你使用

花车时,无论如何,他们会立即提升为双倍计算

。在这种情况下,当然,您也可以不使用

all中的变量并直接打印结果。

printf(" please enter a inches \\\
" );
scanf("%d",& inches_to_input);


你应该检查scanf的返回值,看看它是否成功。

如果因为用户输入one而失败了。那么inches_to_input将不会被初始化,所以程序可能会输出一些随机值。

inches_to_output = inches_to_input * centmeter;
printf(" inches converted is% f\\\
",inches_to_output);
返回0;
}
Am I did the following program corectly according to the question?
It looks to me like it should basically work, although there are some
issues and style matters you should consider.
Question:

/* 1:You have just been employed by MacroMuscle, Inc.
(Software for Hard Bodies). The company is entering the European
market and wants a program that converts inches to
centimeters (1 inch = 2.54 cm). The company wants the
program set up so that it prompts the user to enter an inch
value. Your assignment is to define the program objectives and
to design the program (steps 1 and 2 of the programming process).
*/

solution:

#include<stdio.h>
This would be easier for a human to read with an extra space.

#include <stdio.h>
#define centmeter 2.54
int main(void)
{
int inches_to_input;
Why use an int? It is common for people to deal with fractional inches.
Obviously if you change it you will have to change the scanf format
specifier.
float inches_to_output;
Why use a float rather than a double? Most of the time when you use
floats they get immediately promoted to double for the calculation
anyway. In this case, of course, you could also not use the variable at
all and print the result directly.
printf("please enter a inches\n");
scanf("%d",&inches_to_input);
You should check the return value of scanf to find out if it succeeded.
If it fails because the user entered "one" then inches_to_input would
not be initialised so the program could well output some random value.
inches_to_output = inches_to_input * centmeter;
printf("inches converted is %f\n",inches_to_output);
return 0;
}




一般来说,首次尝试比初学者看到的更多。


本着乐于助人的精神,我还想向您指出

comp.lang.c常见问题,其中包含大量有用信息和

帮助解决您在进步时可能会遇到的问题 http:/ /c-faq.com/

-

Flash Gordon

生活在有趣的时代。

虽然我的电子邮件地址是垃圾邮件,但它是真实的,我读了它。



Generally a better first attempt than many we see here from beginners.

In the spirit of being helpful, I would also like to point out the
comp.lang.c FAQ to you which contains a lot of useful information and
help with questions you are likely to ask as you progress http://c-faq.com/
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.


这篇关于初学者#1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆