我怎么能用C或JAVA编写代码 [英] How can I code this in C or JAVA

查看:117
本文介绍了我怎么能用C或JAVA编写代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

N个整数作为输入传递给程序。程序必须打印这N个整数的GCD(HCF)。



输入格式:

第一行包含N.

第二行包含N个整数,每个整数用空格分隔。



输出格式:

第一行包含HCF这些N个数字。



边界条件:

2< = N< = 100



示例输入/输出1:

输入:

4

15 20 30 50



输出:

5



我尝试了什么: < br $> b $ b

int n;

scanf(%d,& n);

char a [100 ];

scanf(%s,a);

N integers are passed as input to the program. The program must print the GCD (HCF) of these N integers.

Input Format:
The first line contains N.
The second line contains N integers each separated by a space.

Output Format:
The first line contains the HCF of these N numbers.

Boundary Conditions:
2 <= N <= 100

Example Input/Output 1:
Input:
4
15 20 30 50

Output:
5

What I have tried:

int n;
scanf("%d",&n);
char a[100];
scanf("%s",a);

推荐答案

Quote:

int n;

scanf(%d,& n);

char a [100];

scanf(%s,a);

int n;
scanf("%d",&n);
char a[100];
scanf("%s",a);



你看起来没经验。我建议你使用 Java (参见,例如: Java输入和输出(I / O) [ ^ ]。



您的尝试缺少最重要的功能, GCD 计算。请参阅欧几里德算法 - 维基百科 [ ^ ]。


You look inexperienced. I would suggest you using Java (see, for instance: Java Input and Output (I/O)[^]).

Your attempt lacks of the most important feature, the GCD computation. See Euclidean algorithm - Wikipedia[^].


一点点Google搜索为您提供答案:

N个整数的GCD(HCF)(Id-3103) - 代码For Alls ..! [ ^ ]



A little Google search gives you an answer:
GCD (HCF) of N Integers (Id-3103) - Code For Alls..![^]

引用:

我如何在C或JAVA中编码?

How can I code this in C or JAVA



您将永远不会通过尝试解决此类问题来学习编码。请注意,这个问题很简单,你无法解决它。

建议:

- 正确学习编码,找一些教程并遵循它们。

- 阅读文档。

- 学习一种或多种分析方法, EW Djikstra自上而下的方法是一个良好的开端。

https:// en.wikipedia.org/wiki/Top-down_and_bottom-up_design [ ^ ]

https://en.wikipedia.org/wiki/Structured_programming [ ^ ]

https://en.wikipedia.org/wiki/Edsger_W._Dijkstra [ ^ ]

https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF [ ^ ]



Nota:这是一种简单的方法。


You will never learn coding by trying to solve such problems. Note that this problem is rather simple and you are unable to solve it.
Advice:
- Learn coding properly, find some tutorials and follow them.
- Read documentation.
- Learn one or more analyze methods, E.W. Djikstra top-Down method is a good start.
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design[^]
https://en.wikipedia.org/wiki/Structured_programming[^]
https://en.wikipedia.org/wiki/Edsger_W._Dijkstra[^]
https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF[^]

Nota: this is the easy way.


这篇关于我怎么能用C或JAVA编写代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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