C语言期末考试编程题

发布网友

我来回答

4个回答

热心网友

1输入两个整数a和b,若a和b的平方和大于100,则输出平方和的百位以上的数字,否则输出a和 b的和。
要求: 1)输出结果时说明平方和是大于100还是小于100( >100或<100 )
#include<stdio.h>
int main(){
int a, b, c;
scanf("%d%d", &a, &b);
c = a * a + b * b;
if(c > 100) printf("平方和大于100\n%d\n", c%100);
else printf("平方和小于等于100\n%d\n", a + b);
return 0;
}
2输入一个整数,判断是否是5和7的公倍数,若是则输出:5and7yes,否则再判断是否是3的倍数,若是3的倍数输出:3yes,若都不是则输出:no
#include<stdio.h>
int main(){
int input;
scanf("%d", &input);
if(input % 5 == 0 && input % 7 == 0)printf("5and7yes\n");
else if(input % 3 == 0) printf("3yes\n");
else printf("no\n");
return 0;
}
第三,四题和第二题差不多
5计算公式: [ 2*x x=2
y= [ x*x+1 x<2
[ 2*x*x+3*x+1 x>2
要求: 1)从键盘输入x的值,根据x的值求y的值
2)输出y的值
#include<stdio.h>
int main(){
int x, y;
scanf("%d", &x);
if(x == 2) y = 2*x;
else if(x < 2) y = x*x+1;
else y = 2 * x * x + 3 * x + 1;
printf("%d\n", y);
return 0;
}
8 和7差不多
下面原理都差不多 用if基本都能搞定 判断条件就行了 应该LZ能搞定了 东西有点多 -。- 就写这些吧 其他的就不一一写了^ ^

热心网友

1、
#include <stdio.h>
main()
{
int a, b, square;
scanf (“%d%d”, &a, &b);
square = a * a + b * b;
if (square > 100) \*判断a、b的平方和是否大于100 *、
{
printf (“their square is bigger than 100\n”);
printf (“the digitale bigger than 100 is :%d”, square / 100);
}
else
{
printf (“their square is smaller than 100\n”);
printf (“their addtion is: %d”, a + b);
}
}
2、
#include <stdio.h>
main()
{
int n;
if ((n % 5 == 0) && (n % 7 == 0)) \* 判断n是否为5和7的公倍数 *\
{
printf (“5 and 7 yes”);
}
else
{
if (n % 3 == 0) \* 判断是否能被3整除 *\
printf (“ 3 yes”);
else
printf (“no”);
}
}
3、(3题和平共处题与第2题相似的,只要把条件改一下就可以了)
#include <stdio.h>
main()
{
int n;
if ((n % 3 == 0) && (n % 5 == 0))
{
printf (“3 and 5 yes”);
}
else
{
if (n % 7 == 0)
printf (“ 7 yes”);
else
printf (“no”);
}
}
4、
#include <stdio.h>
main()
{
int n;
if ((n % 2 == 0) && (n % 3 == 0))
{
printf (“2&3 yes”);
}
else
{
if (n % 7 == 0)
printf (“ 3 yes”);
else
printf (“no”);
}
}
5、
#include <stdio.h>
main()
{
int x, y;

printf ("x =");
scanf ("%d", &x);
if (x == 2) \* 用一个多分支语句将几种情况分开计算*\
y = 2 * x;
else if (x < 2)
y = x * x + 1;
else
y = 2 * x * x + 3 * x + 1;
printf ("y = %d", y);
}

6、(6 题和7题还有8题都与5题相似)
#include <stdio.h>
main()
{
int x, y;

printf ("x =");
scanf ("%d", &x);
if (x == 1)
y = 1;
else if (x < 1)
y = x * x;
else
y = x * x * x;
printf ("y = %d", y);
}

7、
#include <stdio.h>
main()
{
int x, y;

printf ("x =");
scanf ("%d", &x);
if (x < 0)
y = x + 1;
else if (x <= 2)
y = x * x + 2;
else
y = x * x * x + 3;
printf ("y = %d", y);
}
8、
#include <stdio.h>
main()
{
int x, y;

printf ("x =");
scanf ("%d", &x);
if (x < 1)
y = x;
else if (x <= 10)
y =2 * x - 1;
else
y = 3 * x - 11;
printf ("y = %d", y);
}
9、
#include <stdio.h>
main()
{
float score;
char grade;

printf ("please enter the score:");
scanf ("%f", &score);
if (score > 100 || score < 0) \*判断成绩是否输入正确*\
{
printf ("enter error!");
}
if (score >= 90)
grade = 'A';
else if (score >= 80)
\*在这里的else if 语句条件中已经排除了在于等于90的情况,即此处等同于"score >= 80 && score < 90"*\
grade = 'B';
else if (score >= 70)
grade = 'C';
else if (score >= 60)
grade = 'D';
else
grade = 'E';
printf ("the grade is :%c", grade);
}
10、
#include <stdio.h>
main()
{
int n, price;

printf ("please enter quantity:");
scanf ("%d", &n);
if (n <= 10)
price = 60;
else if (n < 40) \* 此处方法与上题相同*\
price = 50;
else
price = 45;
printf ("the total money is :%d", price * n);
}
11、
#include <stdio.h>
#include <math.h>
main()
{
int a, b,final;

printf ("enter a,b:");
scanf ("%d%d", &a, &b);
if (a % b == 0)
final = a * a + b * b;
else if ( b % a == 0)
final = a * a * a + b * b * b;
else
final = abs(a - b);
printf ("final = %d", final);
}
12、
#include <stdio.h>
#include <math.h>
main()
{
float a, b, f;

printf ("enter a,b:");
scanf ("%f%f", &a, &b);
if (a > b)
f = fabs(a - b);
else if (a < b)
f = a * b;
else
f = ((int)a % 10) * ((int)b % 10); \*用强制转换将a、b转换成整数再除10求余即得个位数字*\
printf ("f = %.2f", f);
}

13、
#include <stdio.h>
#include <math.h>
main()
{
int a, b, c, disc;
int x1, x2,x;

printf ("a,b,c=");
scanf ("%d%d%d", &a, &b, &c);

if (a == 0)
{
printf ("this is not a equation");
}
else
{
disc = b * b - 4 * a * c;
if ( disc > 0)
{
x1 = (- b + sqrt(disc)) / (2 * a);
x2 = - b - sqrt(disc) / (2 * a);
printf ("there are two deferent root:%d %d", x1, x2);
}
else
{
x = - b / ( 2 * a);
printf ("there are two same root:%d", x);
}
}
}
14、
#include <stdio.h>
main()
{
int n;
int n1, n2, n3;

printf ("please enter a number:");
scanf ("%d", &n);
if (n >= 100 && n <= 999)
{
n1 = n / 10;\*取出n的个、十、百各位数*\
n2 = (n - n1* 10) / 10;
n3 = n % 10;
if (n1 * n1 * n1 + n2 * n2 * n2 + n3 * n3 * n3 == n)\* 判断个、十、百位平方和是否等于n *\
printf ("the number is shuixianhua digitale");
else
printf ("the number is not shuixianhua digitale");
}
else
printf ("the number is not a 3 bit number");
}
15、
#include <stdio.h>
main()
{
enum workday {monday = 1, tuesday, wednesday, thursday, friday, saturday, sunday};
enum workday workdays;
int n;

printf ("please enter a days:");
scanf ("%1d", &n);
if (n >= 1 && n <= 7)
{
workdays = (enum workday)n;
switch(workdays)
{
case 1: printf ("moday"); break;
case 2: printf ("tuesday"); break;
case 3: printf ("wednesday"); break;
case 4: printf ("thursday"); break;
case 5: printf ("friday"); break;
case 6: printf ("saturday"); break;
case 7: printf ("sunday"); break;
}
}
else
printf ("enter error");
}


16、
#include <stdio.h>
main()
{
int i, n;
float t, s = 0; \* 用t 产生各项,s 为各项之和 *\
printf ("n = ");
scanf ("%d", &n);
for (i = 1; i <= n; i++)
{
t = 1.0 / n; \* 因为n 是整数,在1后面加小数使得结果不至于为零*\
s = s + t;
n = n + 2;
}
printf ("the addtion is :%f", s);
}


热心网友

这么简单的程序自己怎么不写啊,这是多么基础的啊!

热心网友

30分就帮你编16个程序!?你在做梦吧?!

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com