谁能帮我做下c语言这道题

来源:百度知道 编辑:UC知道 时间:2024/05/28 19:05:04
x+a%3*(int)(x+y)%2/4
设x=2.5,a=7,y=4.7
太棒啦~!!哈哈~太感谢你啦~!!

#include "stdio.h"

int main()
{
double x=2.5;
double y=4.7;
int a=7;

printf("%f",x+a%3*((int)(x+y)%2)/4);
return 0;
}

1.算(x + y) = 7.2
2.(int)强制转换是四舍五入的,即等于7;
3.从左到右按优先级算,a%3 = 7%3 = 1,即求余数;
4.求a%3*(int)(x+y) = 1 * 7 = 7;
5.求a%3*(int)(x+y)%2 = 7 % 2 = 1;
6.求a%3*(int)(x+y)%2/4 = 1 / 4 = 0;
7.求x+a%3*(int)(x+y)%2/4 = x + 0 = 2.5

#include<iostream>
using namespace std;
int main()
{
float x=2.5,a=7,y=4.7;
cout<<x+a%3*(int)(x+y)%2/4<<endl;
}

2.5