解決済みの質問
プログラミングC言語の問題です
プログラミングC言語の問題です
キーボードから5つの数字を入力し、その合計、最小値、最大値、平均値を画面に表示するプログラムを作成してください。分かる方がいらっしゃれば至急お願いします。
-
- 質問日時:
- 2012/1/30 21:03:49
-
- 解決日時:
- 2012/2/14 12:02:04
-
- 回答数:
- 3
-
- お礼:
- 知恵コイン
- 250枚
-
- 閲覧数:
- 82
-
- ソーシャルブックマークへ投稿:
- Yahoo!ブックマークへ投稿
- はてなブックマークへ投稿
- (ソーシャルブックマークとは)
この質問は投票によってベストアンサーが選ばれました!
- この質問・回答は役に立ちましたか?
- 役に立った!
お役立ち度:
0人が役に立つと評価しています。
ベストアンサー以外の回答
(2件中1〜2件)
- 並べ替え:回答日時の
- 新しい順
- |
- 古い順
C++やろうぜC++
,は空白
#include<conio.h>
#include<iostream>
#include<boost/tuple/tuple_io.hpp>
#include<boost/algorithm/minmax.hpp>
#include<boost/algorithm/minmax_element.hpp>
using namespace std;
const int numofar = 5;
int main(){
,,,,int arr[numofar];
,,,,int total = 0;
,,,,for(int i = 0; i < numofar;i++){
,,,,,,,,cin >> arr[i];
,,,,,,,,total += arr[i];
,,,,}
,,,,pair<int*, int*> r = boost::minmax_element(&arr[0],&arr[5]);
,,,,cout << "合計:" << total << endl;
,,,,cout << "最大値:" << *r.second << endl;
,,,,cout << "最小値:" << *r.first << endl;
,,,,cout << "平均値:" << total/numofar << endl;
,,,,if(getch()) return 0;
}
- 違反報告
- 回答日時:2012/2/6 12:52:53
javaやろうぜjava
java
↓
import java.util.Scanner;
public class Main{
....public static void main(String args[]){
........Scanner stdin = new Scanner(System.in);
........System.out.print("1つ目:");
........double n1 = stdin.nextInt();
........System.out.print("2つ目:");
........double n2 = stdin.nextInt();
........System.out.print("3つ目:");
........double n3 = stdin.nextInt();
........System.out.print("4つ目:");
........double n4 = stdin.nextInt();
........System.out.print("5つ目:");
........double n5 = stdin.nextInt();
........//合計
........System.out.println("合計:" + n1 + n2 + n3 + n4 + n5);
........//最小値
........double[] Array5 = {n1, n2, n3, n4, n5};
........Arrays.sort(Array5);
........System.out.println("最小値:" + Array5[0]);
........//最大値
........System.out.println("最大値;" + Array5[Array5.length - 1]);
........//平均値
........System.out.println("平均値:" + (n1 + n2 + n3 + n4 + n5) / 5);
....}
}
python
↓
#!/usr/bin/python
#coding:utf-8
n1 = float(raw_input(u"1つ目:"))
n2 = float(raw_input(u"2つ目:"))
n3 = float(raw_input(u"3つ目:"))
n4 = float(raw_input(u"4つ目:"))
n5 = float(raw_input(u"5つ目:"))
list = [n1, n2, n3, n4, n5]
list.sort()
print "合計:" + str(n1 + n2 + n3 + n4 + n5)
print "最小値:" + str(list[0])
print "最大値:" + str(list[len(list)-1])
print "平均値:" + str((n1 + n2 + n3 + n4 + n5) / 5)
- 違反報告
- 編集日時:2012/2/6 12:45:57
- 回答日時:2012/2/6 12:41:08

