1、程序的运行效果应类似地如图1所示,图1中的3是从键盘输入的内容。#include int main(void)int x;double y;Please input x:);scanf(%d, &x);if (x 0)y = (double) 2 * x - 1;elseif (x = 0)y = (double) 7909;y = (double) - 5 * x + 27;nF(%d) = %.0lfn, x, y);return 0;2. P1-113已知某银行整存整取存款不同期限的年息利率分别为:3.15%期限一年,3.63%期限二年,4.02%期限三年,4.69%期限五年,5.36%
2、期限八年。从键盘上输入存钱的本金(以元为单位,必须定义为int且应考虑金额很大的情况)和存款期限(只考虑1,2,3,5,8),求到期时能从银行得到的利息(以元为单位,应考虑有小数,不计复利)。编程可用素材:nPleasebenjin,cunqi:).、printf(nlixi=.yuan.。程序的运行效果应类似地如图1所示,图1中的10000,8是从键盘输入的内容。 int benjin, cunqi; double lixi; double money; printf(nPlease input benjin,cunqi: scanf(%d,%dbenjin, &cunqi); money
3、= benjin; if ( cunqi = 1 ) lixi = money * cunqi * 3.15 / 100; else if ( cunqi = 2 ) lixi = money * cunqi * 3.63 / 100; else if ( cunqi = 3 ) lixi = money * cunqi * 4.02 / 100; else if ( cunqi = 5 ) lixi = money * cunqi * 4.69 / 100; else if ( cunqi = 8 ) lixi = money * cunqi *5.36 / 100; nlixi = %.2
4、f yuann, lixi); return 0;3. P1-114编写一个简单计算器程序,输入格式为:data1opdata2。其中data1和data2是参加运算的两个数(data1、data2必须定义为int,但二者相加可能超出int能表示的范围),op为运算符,它的取值只能是+、-、*、/、%。程序的运行效果应类似地如图1、图2、图3、图4所示,图1中的3000+2000、图2中的3000%2000、图3中的30000和图4中的3000/0是从键盘输入的内容。int main( void ) int data1, data2; double jieguo; char op;nPleas
5、e input data1 op data2:%d %c %ddata1, &op, &data2); switch ( op ) case +: jieguo = ( double ) data1 + data2; printf(n%d%c%d=%.0fn, data1, op, data2, jieguo); break;- jieguo = ( double ) data1 - data2;* jieguo = ( double ) data1 * data2;/ if ( data2 != 0 ) jieguo = ( double ) data1 / data2; printf( b
6、reak;nError! chu shu wei 0.n% jieguo = data1 % data2; default:n4.输入月份,打印2003年该月有几天。当输入的月份超范围时,应显示“Invalidmonthinput”。程序的运行效果应类似地如图1和图2所示,图1中的4和图2中的13是从键盘输入的内容。 int month; int day;nplease input the month number:month); switch ( month ) case 1: case 3: case 5: case 7: case 8: case 10: case 12: day = 3
7、1;n2003.%d has %d days.n, month, day); case 4: case 6: case 9: case 11: day = 30; case 2: day = 28;nInvalid month inputn 5.已知某公司员工的保底薪水为500,某月所接工程的利润profit(整数)与利润提成的关系如下(计量单位:元):profit1000没有提成;1000profit2000提成10%;2000profit5000提成15%;5000profit10000提成20%;10000profit提成25%。请根据输入的利润计算员工的薪水。程序的运行效果应类似地如图
8、1所示,图1中的2000是从键盘输入的内容。 int profit; double salary = 500;nInput profit:profit); if ( profit 1000 & profit = 2000 ) salary = salary + profit * 0.1; 2000 &= 5000 ) salary = salary + profit * 0.15; 5000 &= 10000 ) salary = salary + profit * 0.2; 10000 ) salary = salary + profit * 0.25;salary=%.2fn, salary);6.编写一程序P7-708.C实现以下功能输入一个三位正整数,然后逆序输出。如输入123,则输出321。程序的运行效果应类似地如图1所示,图1中的752是从键盘输入的内容。#includestdlib.h/*int main(void) int num, i; char str4;Input an integer:num); itoa(num, str, 10);The result is for(i = 2; i = 0; i-) printf(%c, stri);*/ int num; do, num%10); num = num/10; while (num); print
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1