如何通过If,else语句执行程序? [英] How can I do a program by If, else statement?

查看:67
本文介绍了如何通过If,else语句执行程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要的输出是,

输出:



输入数字(3个数字)= 4,6,3(a ,b,c)<整数



a是中间

b很大而且

c很小。



更多例子:6,6,4<< a,b,c整数



a和b相同而且大小很小。



< br $> b $ b

<<<<像这样!我需要自己不能做的程序。我是新手。我开始c程序。所以,如果你能做得更好,请使用C程序,或者使用C程序。



提前致谢




从PIEBALDconsult的回答中移出 - 清理错误的XML编码有些麻烦,可能仍然存在由此引起的错误,但原始版本肯定存在错误。我尽我所能。



对不起!你介意我的谈话吗?好吧,我真的很抱歉再次:)



无论如何,我这样做了!



I need output is that,
Output:

Enter the numbers (3 numbers)= 4,6,3 (a,b,c) < integer

a is middle
b is big and
c is small.

More example: 6,6,4 << a,b,c integer

a and b is same and c big small from them.



<<<< like this! I need program which I can't do by myself. I am newbie. I start c program. So, please if you can better to do but, if else statement and by using C program.

Thanks in advance


Moved from "answer" by PIEBALDconsult -- some trouble with cleaning up the bad XML encoding, there may still be errors caused by this, but there are certainly bugs in the original. I did what I could.

I am sorry! Did you mind with my talks? Well, I am really sorry again :)

Any way, I did this!

#include <stdio.h>
#include <conio.h>
int main ()
{	int a,b,c;

printf("\nEnter 3 numbers:");
scanf("%d %d %d",&a,&b,&c);

	
	if (a==b && a<c mode="hold" )	{
	
	printf ("a and b is same and small from c");
}
	else if (a==b && a>c || b>c)
	{
	
	printf ("a and b is same and big from c");
}
	else if (a==c && a<b mode="hold" )	{
	
	printf ("a and c is same and small from b");
}
	else if (a==c && a>b || c>b)
	{
	
	printf ("a and c is same and big from b");
}
	else if  (b==c && b>a || c>a)
	{
	
	printf ("b and c is same and big from a");
	
}
break;
	else if ((b==c) && (b<a))	{
	
	printf ("b and c is same and small from a");
}
	else if (a/b && b/c )
	{
	
	printf ("a is big\n b is middle \n c is small");
}
	else
	{
	 
	printf (" is nagitive");
}
	getch ();
}





但我不知道那个错误在哪里。错误即将来临。请你检查一下。这还不完整。



But I don't know where is that error. Error is coming. Please you may check. And this is incomplete yet.

推荐答案

我们不做你的作业:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!



我不会给你代码,但我会给你一个想法。

排序输入(如Bruno建议的那样)是可行的方法,但目前通用排序可能有点困难,如果和<$,你应该使用 c $ c> else 构造。



所以按照这样排序:

1)比较a和b 。如果a大于b,则执行步骤2,否则跳过它。

2)交换a和b。

3)a现在包含越小,b越大。所以比较b和c,并做同样的事情 - 它给你三个中最大的数字c

4)再次比较a和b,并在必要时交换。



a现在包含最小,b中间,c最大。 (这是所谓的冒泡排序的一个非常简单的版本 - 因为它冒泡了列表中最大的值)。



现在你需要做什么正在打印它们。
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

And I'll not give you the code, but I'll give you the idea.
Sorting the inputs (as Bruno suggested) is the way to go, but a generic sort is probably a bit difficult at the moment, and you are supposed to use an if and else construct.

So sort them like this:
1) Compare a and b. If a is bigger than b, then do step 2, otherwise, skip it.
2) Swap a and b.
3) a now contains the smaller, b the larger. So compare b and c, and do the same thing - which give you the largest number of the three in c
4) Compare a and b again, and swap if necessary.

a now contains the smallest, b the middle, and c the largest. (This is a very simple version of what is called a Bubble Sort - because it "bubbles" the largest values up the list).

Now all you need to do is print them.


这篇关于如何通过If,else语句执行程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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