哪個老大
可以幫我思考看看
1. 請寫一個程式,使其輸出結果為第一個數值是第二個數值的多少百分比(取小數
點以下4 位)。
其執行範例如下:
數值A:54
數值B:84
A是B的64.2857%
2. 請寫一個程式,輸入兩個整數值A、B;若兩個整數值相等,則輸出『A等於B』;
若A較大,則輸出『A 大於B』;若B較大,則輸出『B大於A』。
使用1一個選擇的if敘述及2多重選擇的if敘述來寫程式
3. 請寫一個程式,輸入三個整數值;若三個整數值均相等,則輸出『此三個數值
相等』;若任兩個數值相等,則輸出『有兩個數值相等』;若以上皆非,則輸出
『此三個數值相異』。
4. 請寫一個程式,計算1+3+5…+99
5. 請寫一個程式,計算n!
提示:n! = n*(n-1)*(n-2)*…..*1
0! = 1
6. 請寫一個程式,輸入非負數的整數,將其由後而前重新排列。
其執行範例如下:
請輸入一個非負數的整數:6475
整數6475 由後而前重新排列的新數是5746

 

answer:

#include "stdafx.h"//visual c++,if is dev c++ del
#include <iostream>
#include <stdio.h>
using namespace std;
int main(int argv,char *argc[])
{
float total=0,one=0,two=0;
cout<<"第一個數值=";
cin>>one ;
cout<<endl<<"第二個數值=";
cin>>two ;
cout<<endl;
total=100*(one/two) ;
cout<<"數值a="<<one<<endl;
cout<<"數值b="<<two<<endl;
cout.precision(6);
cout<<"A是B的"<<total<<"%"<<endl;
return 0;
}
====================================
#include "stdafx.h"
#include <iostream>
using namespace std;
int main(int argc,char *argv[])
{
int one=0,two=0;
cout<<"輸入第一個整數值=";
cin>>one ;
cout<<endl<<"輸入第二個整數值=";
cin>>two;
if(one==two)
{
cout<<"A等於B"<<endl;
}
else if(one>two)
{
cout<<"A大於B"<<endl;
}
else
{
cout<<"B大於A"<<endl;
}
return 0;
}
==========================================
#include "stdafx.h"
#include <iostream>
using namespace std;
int main(int argc,char *argv[])
{
int one,two,three;
cout<<"輸入第一個值=";
cin>>one;
cout<<endl<<"輸入第二個值=";
cin>>two;
cout<<endl<<"輸入第三個值=";
cin>>three;
if((one==two) && (one==three) && (two==three))
{
cout<<"此三個數值相等"<<endl;
}
else if((one==two) || (one==three) || (two==three))
{
cout<<"有兩個數值相等"<<endl;
}
else
{
cout<<"此三個數值相異"<<endl;
}
return 0;
}
============================================
#include "stdafx.h"
#include <iostream>
using namespace std;
int main(int argc, char * argv[])
{
int i,t=0;
for(i=1;i<=99;i++)
{
if((i%2)!=0)
{
t+=i;
cout<<i<<"="<<t<<endl;
}
}
cout<<"total="<<t<<endl;
return 0;}
========================================

參考資料 me

 

arrow
arrow
    全站熱搜

    mitblog 發表在 痞客邦 留言(0) 人氣()