伊莉討論區's Archiver

copyright


頁: [1]

93GM 發表於 2009-11-20 11:04 AM

C++題目!徵求高手幫忙

[i=s] 本帖最後由 93GM 於 2009-11-20 01:26 PM 編輯 [/i]

設計一個C++的程式,可輸入n個整數,n為由鍵盤輸入,並顯示求出由大到小順序之資料,程式並可重複執行。

設計一個C++的程式,可輸入兩個整數,選擇任一四則運算,並將答案顯示在螢幕上,程式並可重複執行。(ps: 0不得當被除數)

這兩題需要高手指導一下
能用最簡便的方法寫出來嗎
用if/for...等


|
[p=30, 2, left][color=#000000][b][font=新細明體][size=10pt][font=Times New Roman]Q:[/font]設計一個[/size][/font][/b][b][size=10pt][font=Times New Roman]C++[/font][/size][/b][b][font=新細明體][size=10pt]的程式,可求出所有三位數之百位數、十位數、個位數之立方和等於原數者,並寫出共有幾組答案。[/size][/font][/b][/color][/p][p=30, 2, left][color=#000000][/color][/p][p=30, 2, left][color=#000000][b][font=新細明體][size=10pt]附加這題目 希望能有人幫忙![/size][/font][/b][/color][/p][p=30, 2, left][b][font=新細明體][size=2][color=#000000][/color][/size][/font][/b] [/p][p=30, 2, left][b][font=新細明體][size=2][color=#000000]|[/color][/size][/font][/b][/p]

daviddr 發表於 2009-11-20 12:04 PM

第二題,用 VC++ 編譯:[code]#pragma comment(linker,"/entry:e")
#define o(_) if(*#_ ==c&&(c^'/'||b)) a _= b;
#include <iostream>
using namespace std;
float a,b;
char c;
void e()   
{     
    cout <<"\n輸入算式: ";
    cin >>a >>c >>b;
    o(+)o(-)o(*)o(/)
    cout <<a; e();   
}[/code]

93GM 發表於 2009-11-20 01:27 PM

[b]回復 [url=http://www.eyny.com/redirect.php?goto=findpost&pid=86626284&ptid=4025241]2#[/url] [i]daviddr[/i] [/b]


    謝謝指導!
希望能把另外兩題目也幫忙寫出來~

93GM 發表於 2009-11-20 01:58 PM

[b]回復 [url=http://www04.eyny.com/redirect.php?goto=findpost&pid=86626284&ptid=4025241]2#[/url] [i]daviddr[/i] [/b]


    是可以輸入數字  但是計算的時候出現亂碼了@@

daviddr 發表於 2009-11-20 03:54 PM

> 出現亂碼
要照程式給的格式輸入。
如:3.14159*2

daviddr 發表於 2009-11-20 04:36 PM

第一題,用 VC10 編譯:[code]#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    for (int n, i=0, v[256];;) {
        cout << "\n輸入個數: ";
        for (cin>> n; i<n; cin>>v[i++]);
        sort (v, v+n, [](int a, int b){return a>b;});
        for_each (v, v+n, [](int x) {cout <<' '<<x;});
    }
}[/code]

daviddr 發表於 2009-11-21 01:30 AM

[i=s] 本帖最後由 daviddr 於 2009-11-21 01:49 AM 編輯 [/i]

(3) write only.. 參考就好..[code]#include <iostream>
using namespace std;

int main()
{
    #define C n[x] = x*x*x; x++
    int a=1, b=0, c=0, x=0;
    int n[10]; {C,C,C,C,C,C,C,C,C,C;}
     
    for (x=99; ++x < 1000;
        ++c > 9 && (c=0, ++b > 9) && (b=0, ++a))
        if (x == n[a]+n[b]+n[c]) cout <<' '<< x;
}[/code]

頁: [1]

Powered by Discuz! Archiver 7.1  © 2001-2009 Comsenz Inc.