初学者,求C语言编程计算表达式的值,每个都要写一个程序吗?急急急,作业帮帮忙 (3) 2.5+2*7%2/4
(1)1200/(24-4*5)(4)3*(int)sqrt(34)-sin(6)*5+0x2AF(5)4.5+8%5*(int)(2.7+4.5)/2%4有没有可以输入...
(1)1200/(24-4*5)
(4) 3*(int)sqrt(34)-sin(6)*5+0x2AF
(5) 4.5+8%5*(int)(2.7+4.5)/2%4
有没有可以输入该表达式出结果的程序 ? 展开
(4) 3*(int)sqrt(34)-sin(6)*5+0x2AF
(5) 4.5+8%5*(int)(2.7+4.5)/2%4
有没有可以输入该表达式出结果的程序 ? 展开
展开全部
Endys-MBP:Desktop endy$ vi test.c
Endys-MBP:Desktop endy$ gcc -o test test.c
Endys-MBP:Desktop endy$ ./test
================Start================
(1)--1200/(24-4*5)=300
(3)--3*(int)sqrt(34)-sin(6)*5+0x2AF=703
(4)--2.5+2*7%2/4=2
(5)--4.5+8%5*(int)(2.7+4.5)/2%4=6
================End================
Program exit normally!
Endys-MBP:Desktop endy$ cat test.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define NONE "\033[m"
#define RED "\033[0;32;31m"
// exit function
void do_at_exit(void)
{
printf("Program exit normally!\n\n");
}
// main function
int main()
{
// variable definition
float answer = .0;
int flag = 0;
// caculation
answer = 1200 / (24 - 4 * 5);
printf(RED"\n\n\n================Start================\n");
printf("(1)--1200/(24-4*5)=%.0f\n\n", answer);
answer = 3*(int)sqrt(34)-sin(6)*5 + 0x2AF;
printf("(3)--3*(int)sqrt(34)-sin(6)*5+0x2AF=%.0f\n\n", answer);
answer = 2.5 + 2 * 7 % 2 / 4;
printf("(4)--2.5+2*7%%2/4=%.0f\n\n", answer);
answer = 4.5 + 8 % 5 * (int)(2.7 + 4.5) / 2 % 4;
printf("(5)--4.5+8%%5*(int)(2.7+4.5)/2%%4=%.0f\n", answer);
printf("================End================\n\n\nNONE);
// register callback function
flag = atexit(do_at_exit);
if (flag)
{
printf("Cannot register exit function!errorcode:%d\n", flag);
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询