数学11—1 C语言平时训练题
1、算术基本运算
Description
计算两整数x和y(0〈x,y<1000)的和、差、积、商、余数、x的平方和y的三次方。
Input
输入只有一行.
Output
输出为多行,按顺序每行输出x,y的和、差、积、商、余数、x的平方和y的三次方
Sample Input
x = 11, y = 3
Sample Output
x + y : 14
x - y : 8   
x * y : 33
x / y quotient: 3, remainder: 2
x ^ 2 : 121
y ^ 3 : 27
Answer
#include 〈stdio.h>
int main()
{
    int x,y,a,b,c,d,e,f,g;
    0<x〈1000,0<y<1000;
    scanf(”x = %d, y = %d”,&x,&y);
    a=x+y;
    b=x-y;
    c=x*y;
    d=x/y;
    e=x%y;
    f=x*x;
    g=y*y*y;
    printf(”x + y : %d\n”,a);
    printf("x - y : %d\n",b);
    printf("x * y : %d\n”,c);
    printf("x / y quotient: %d, remainder: %d\n”,d,e);
    printf(”x ^ 2 : %d\n”,f);
    printf(”y ^ 3 : %d\n”,g);
    return 0;
2、求圆的面积和周长
Description
从键盘输入圆的半径,求圆的面积和周长,圆周率取3.14。
Input
输入一个浮点型数据,有效数字不会超过十进制的6位。
Output
输出为两行。
第一行为圆的面积,第二行为圆的周长,格式见sample。
Sample Input
3
Sample Output
Area: 28。260000
Perimeter: 18.840000
Answer
#include〈stdio。h〉
#define PI 3.14
int main()
{
    float r,s,c;
    scanf("%f”,&r);
    s=PI*r*r;
    c=2*PI*r;
    printf("Area: %f\n",s);
    printf(”Perimeter: %f\n”,c);
    return 0;
}
3、 平均值
Description
求3个数的平均值。
Input
输入只有一行,为3个较小的整数.
Output
输出为这3个整数的平均值,保留3位小数。
Sample Input
1 2 3
Sample Output
2。000
Answer
#include 〈stdio.h>
int main()
    int a,b,c;
    float d;
    scanf(”%d %d %d",&a,&b,&c);
    d=(a+b+c)/3。0;
    printf("%.3f\n",d);
    return 0;
}
4、货币兑换
Description
给出人民币对美元、欧元、日元的当日汇率,求给定金额的人民币能兑换成外币的金额,求给定金额的外币能兑换成人民币的金额。
要计算的外币有三种:美元、欧元、日元。
Input
输入有三行。
第一行依次为美元、欧元、日元外币汇率,用空格分开.汇率用100外币为单位,精确到小数点后4位,如668.5200表示“100美元=668.5200人民币”。汇率浮动范围为(0,10000).
第二行为外币金额x,第三行为人民币金额y。x,y均为整数,且0〈x,y<10000。
Output
输出为两行。
第一行为金额为x的美元、欧元、日元兑换成人民币的金额,用空格分开。
第二行为金额为y的人民币兑换成美元、欧元、日元的金额,用空格分开。
所有金额精确到小数点后两位。
Sample Input
668。5200 908。0685 7。9852
1500
1500
Sample Output
10027.80 13621.03 119。78
224。38 165。19 18784.75
Answer
#include <stdio。h>
int main()
{
    double x,y,a,b,c,d,e,f,g,h,i;
    scanf("%lf%lf%lf”,&a,&b,&c);
    scanf(”%lf”,&x);
    scanf(”%lf”,&y);
    d=x/100*a;
    e=x/100*b;
    f=x/100*c;
    g=y/a*100;
    h=y/b*100;
    i=y/c*100;
    printf("%.2lf %.2lf %。2lf\n",d,e,f);
    printf("%。2lf %。2lf %。2lf\n",g,h,i);
    return 0;
5、 求字符的值
Description
从键盘输入3个字符(不含双字节字符),分别输出每个字符的十进制值(ASCII码)、八进制值和十六进制值。
Input
输入为3个字符。
Output
输出为3行。
每一行为每个字符(对应输入顺序)的十进制、八进制和十六进制值,用空格分隔开.每个输出的值占3个字符,不足3个字符前面补0。
Sample Input
0 A
Sample Output
048 060 030
032 040 020
065 101 041
Answer
#include <stdio。h〉
int main()
{
    char a,b,c;
    scanf(”%c%c%c",&a,&b,&c);
    printf(”%。3d %。3o %。3x\n",a,a,a);
    printf("%。3d %。3o %.3x\n”,b,b,b);
    printf("%。3d %。3o %.3x\n",c,c,c);
c语言六种基本语句  return 0;
6、 奇数还是偶数?
Description
输入一个整数,判读它是奇数还是偶数.
Input
输入只有一行,为一个100以内的正整数。
Output
输出为一行。
若输入为偶数则输出“even",奇数输出“odd”。
Sample Input
30
Sample Output
even
Answer
#include <stdio。h〉
int main()
{
    int a; 
    scanf(”%d”,&a);
    if(a>=0&&a<=100)
{
if (a%2==0)
        printf(”even\n”);
    else
        printf("odd\n");
    }
    else
        printf(”error”);
    return 0;
7、绝对值
Description
求整型数据和浮点型数据的绝对值。
Input
输入两个数,第一个是整数,第二个是浮点数。
Output
输出为两行,第一行为整数的绝对值,第二行为浮点数的绝对值,注意浮点数的绝对值不输出无意义的0。
Sample Input
-1
1
Sample Output
1
1
Answer
#include<stdio.h〉
#include<math。h>
#include〈stdlib。h〉
int main()
    int a,c;
    double b,d;
    scanf(”%d\n%lf",&a,&b);
    c=abs(a);
    d=fabs(b);
    printf("%d\n%g",c,d);
    return 0; 
8、简单的打折计算
Description
商店规定:消费满n元,可以打八八折。设某件商品标价m元,输入购买的件数x,计算出需要支付的金额(单位:元),精确到分。
Input
输入只有一行,三个整数m、n和x,且0〈x〈m〈n<1000。
Output
输出金额,精确到分。
Sample Input
95 300 4
Sample Output
334。40
Answer
#include <stdio.h>
int main()
{
  int m,x,n,a;
  float b;
  scanf(”%d%d%d",&m,&n,&x);