最新c语言实验题.docx
Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-datec语言实验题c语言实验题(1)计算某个数x的平方y,并分别以“y = x*x”和“x*x = y”的形式输出x和y的值。#include <stdio.h>int main()double x,y;printf("Please input x:");scanf("%lf",&x);y = x * x;printf("%f * %f = %fn",x,x,y);printf("%f = %f * %f",y,x,x);return 0;(2) 编程题。求华氏温度150°F对应的摄氏温度。计算公式如下,其中:c表示摄氏温度,f表示华氏温度。c = (5/9)*f-(5/9)*32#include <stdio.h>int main()int f = 150;int c;c = 5 * f/9-(5 * 32)/9;printf("f = %d,c = %d",f,c); return 0;(3)求摄氏温度26°C对应的华氏温度。计算公式如下,其中:c表示摄氏温度,f表示华氏温度。#include <stdio.h>int main()int f;int c = 26; f = (9 * c/5 )+ 32;printf("c = %d,f = %d",c,f); return 0;(4)编程题已知某位学生的数学、英语和计算机课程的成绩分别是87分、72分和93分,求该生3门课程的平均分。#include <stdio.h>int main()int math = 87;int eng = 72;int comp = 93;int average;average = (math + eng + comp)/3;printf("math = %d,eng = %d,comp = %d, average = %d",math,eng,comp,average); return 0; (5)编程题当n为152时,分别求出n的个位数字(digit1)、十位数字(digit2)和百位数字(digit3)的值。#include <stdio.h>int main()int n = 152;int digit1,digit2,digit3;digit1 = n % 10;digit2 =(n/10) % 10;digit3 = n/100;printf("n = %d,digit1 = %d,digit2 = %d,digit3 = %d",n,digit1,digit2,digit3); return 0;思考:如果n是一个四位数,如何求出它的每一位数字。个位;n%10 十位;(n/10)%10 百位:(n/100)%10 千位;n/1000(6)编程题输入存款金额money、存期year和年利率rate,根据下列公式计算存款到期时的利息interest(税前),输出时保留2位小数。#include <stdio.h>#include <math.h>int main()int money,year;double rate,interest;printf("Please input money = n");scanf("%d",&money);printf("Please input year = n ");scanf("%d",&year);printf("Please input rate = n");scanf("%lf",&rate);interest = money * pow(1+rate),year ) - money; printf("money = %d,year = %d,rate = %f,interest = %.2f",money,year,rate,interest); return 0;(7)编程题输入一个四位数,将其加密后输出。方法是将该数每一位上的数字加9,然后除以10取余,作为该位上的新数字,最后将千位和十位上的数字互换,百位和各位上的数字互换,组成加密后的新四位数。#include <stdio.h>int main()int n1,n2,ge,shi,bai,qian;printf("input n1n");scanf("%d",&n1); ge = n1 % 10; shi = (n1/10) % 10; bai = (n1/100) % 10; qian = n1/1000; n2 = (bai + 9)%10 + (qian + 9)%10) *10 + (ge + 9)%10) * 100 + (shi + 9)%10) * 1000; printf("n2 = %d",n); return 0;-