基础C++作业

来源:百度知道 编辑:UC知道 时间:2024/05/23 00:19:35
Write C++ statements that accomplish the following.

(a) Declare int variables x and y. Initialize x to 25 and y to 18.

(b) Declare and initializes an int variable temp to 10 and a char variable ch to 'A'.

(c) Updates the value of an int variable x by adding 5 to it.

(d) Declares and initialize a double variable payRate to 12.50.

(e) Copy the value of an int variable firstNum into an int variable tempNum.

(f) Swap the contents of the int variables x and y. (Declare additional variables, if necessary.)

(g) Suppose x and y are double variables. Output the contents of x, y, and the expression
x + 12 / y - 18.
可以具体点吗,有加分

a)int x, y; //声明变量x,y
x = 25;
y = 18; //初始化变量x,y
b)int temp = 10;
char ch = 'A'; //声明并且初始化变量
c)x += 5; //x更新为x+5
d)double payRate = 12.50;//声明并且初始化
e)tempNum = firstNum;
//firstNum的值赋给tempNum
f)int swap=0;
swap = x;
x = y;
y = swap; //交换x,y的值
g)printf("%lf,%lf,%lf",x,y,(x+(12/y)-18));
打印x,y, x+12/y-18的值

int x=25,y=18;

int temp=10;
char ch='A';

x=x+5;

double payRate=12.50;

int firstNum=10,tempNum;
strcpy(tempNum,firstNum);

int iSwap;
iSwap=x;
x=y;
y=iSwap;

printf("%f%f%f",x,y,(x+12/y-18));

printf输出double应该是%f
scanf输入double用%if