1. 請建立C程式計算下列運算式的值

2x2-4x+1, x=3.0

2. 建立C程式將下列八和十六進位值轉換成十進位值顯示

0277

0xcc

0xab

0333

0xff

3. 現有200個蛋, 一打12個, 請設計一個C程式計算200個蛋是幾打, 還剩下幾個蛋

4. 請用程式計算下列運算, 輸出各個變數值為多少

c=4+(a=3+(b=4+5))

d=2*4>3*5

 

answer:

#include "stdafx.h" //不是VC可刪除該標頭
#include<iostream>
#include<iomanip>

using namespace std;

int main(int argc,char *argv[])
{

float x=3.0; //1

int oc_t=0277,oc_t2=0333,he_x=0xcc,he_x2=0xab,he_x3=0xff; //2

int egg=200; //3

int a,b,c,d; //4

//1. 請建立C程式計算下列運算式的值
cout<<2*x*2-4*x+1<<endl;

//2. 建立C程式將下列八和十六進位值轉換成十進位值顯示
cout.setf(ios::dec);
cout<<"0277==>"<<oc_t<<endl;
cout<<"0333==>"<<oc_t2<<endl;
cout<<"0xcc==>"<<he_x<<endl;
cout<<"0xab==>"<<he_x2<<endl;
cout<<"0xff==>"<<he_x3<<endl;

//3. 現有200個蛋, 一打12個, 請設計一個C程式計算200個蛋是幾打, 還剩下幾個蛋

cout<<"200個蛋是"<<egg/12<<"打"<<endl;
cout<<"還剩下"<<egg-((egg/12)*12)<<"個蛋"<<endl;

//4. 請用程式計算下列運算, 輸出各個變數值為多少
c=4+(a=3+(b=4+5)) ;

d=2*4>3*5 ;

cout<<"a="<<a<<"、b="<<b<<"、c="<<c<<"、d="<<d<<endl;

system("pause");
return 0;
}

參考資料 me

 

arrow
arrow
    全站熱搜

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