C语言实验报告
实验1-1
hello world程序:
源代码:
#include<stdio.h>
main()
{
      printf("hello world!\n");
      system("pause");
      }
实验1-2
完成3个数据的输入、求和并输出计算结果的程序:
源代码:
#include<stdio.h>
main()
{
      int i,j,k,sum;
      scanf("%d%d%d",&i,&j,&k);
      sum=i+j+k;
      printf("sum=%d",sum);
      system("pause");
     
实验1-3
在屏幕上输出如下图形:
A
              BBB
            CCCCC
源代码:
#include<stdio.h>
main()
{
      printf("  A\n");
      printf("  BBB\n");
      printf(" CCCCC\n");
      system("pause");
      }
实验2-1
计算由键盘输入的任何两个双精度数据的平均值
源代码:
#include<stdio.h>
main()
{
      double a,b;
      scanf("%lf%lf",&a,&b);
      printf("%.1lf\n",(a+b)/2);
      system("pause");
      }
实验2-2
写一个输入7个数据的程序,把输入的数据代入a + b * (c – d ) / e * f – g 表达式进行运算
源代码:
#include<stdio.h>
main()
{
      float a,b,c,d,e,f,g,x;
      scanf("%f%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f,&g);
      x=a + b * (c - d ) / e * f - g;
      printf("x=%f",x);
      system("pause");
      }
实验2-3
编写一个C语言程序,测试下列各表达式:
    i, j
    i + 1 , j + 1
    i++ , j++
    ++i , ++j
    i+++++j
源代码:
#include<stdio.h>
main()
{
      int i=1,j=1;
      printf("%d %d\n",i+1,j+1);
      printf("%d %d\n",i++,j++);
      printf("%d %d\n",++i,++j);
      printf("%d\n",(i++)+(++j));
      system("pause");
      }
实验2-4
输入存款金额money,存期year和年利率rate,根据下列公式计算存款到期时的利息interest(税前),输出时保留2位小数。
            interest = money(1+rate)year - money
源代码:
#include<stdio.h>
#include<math.h>
main()
{
      int year=2;
      float rate=0.1,money=1000;
      float futureMoney;
      futureMoney=money*pow((1+rate),year);
      printf("%10.2f",futureMoney);
      system("pause");
      }
实验2-5
输入华氏温度,输出对应的摄氏温度。计算公式如下:
              c = 5 * ( f - 32) / 9
    其中,c表示摄氏温度,f表示华氏温度
源代码:
#include<stdio.h>
main()
{
    int c,f;
    scanf("%d",&f);
    c = 5 * ( f - 32) / 9;
    printf("%d",c);
    system("pause");
}
实验3-1
编写一个程序完成输入一个整数,输出它的符号
源代码:
#include<stdio.h>
main()
{
      int i;
      scanf("%d",&i);
      if(i>0)
      printf("+");
      else
      printf("-");
      system("pause");
      }
实验3-2
请编写居民应交水费,并提供各种测试数据。
    居民应交水费y(元)与月用水量x(吨)的函数关系式如下:
                              0                x < 0
                  y = f(x) =    4x / 3        0 x 源代码大电影 15
                              2.5x – 10.5        x > 15
源代码:
#include<stdio.h>
main()
{
    float x,y;
    scanf("%f",&x);
    if(x<0)
    printf("0");
    else if(x>=0&&x<=15)
    {
        y=4*x/3;
    printf("%f",y);
    }
    else if(x>15)
    {
        y=2.5*x-10.5;
    printf("%f",y);
    }
    system("pause");
}
实验3-3
请根据输入的学生成绩给出成绩等级的判断,判断规则如下:
    如果输入的成绩大于等于90,则输出优秀;
    如果输入的成绩小于90、大于等于80,则输出良好;
    如果输入的成绩小于80、大于等于70,则输出中等;
    如果输入的成绩小于70、大于等于60,则输出及格;
    其他输出不及格
源代码:
#include<stdio.h>
main()
{
    int x;
    scanf("%d",&x);
    if (x>=90)
    printf("优秀\n");
    else if (x>=80&&x<90)
    printf("良好\n");
    else if (x>=70&&x<80)
    printf("中等\n");
    else if (x>=60&&x<70)
    printf("及格\n");
    else
    printf("不及格\n");
    system("pause");
}
实验3-4
运输公司对用户计算运费。路程(s)越远,每公里运费越低。标准如下:
    s = 250km                  没有折扣
    250km s < 500km        2%折扣
    500km s < 1000km        5%折扣
    1000km s < 2000km        8%折扣
    2000km s < 3000km        10%折扣
    3000km s                15%折扣
    设每公里每吨货物的基本运费为p,货物重为w,距离为s,折扣为d,则总运费的计算公式为:
              f = p * w * s * ( 1 – d )
    请编程实现:从键盘输入基本运费p,货物重w,距离s,计算输出用户最终需要支付的运费
源代码:
#include<stdio.h>
main()
{
    int p,w,s,f;
    scanf("%d%d%d",&p,&w,&s);
    float d;
    f = p * w * s * ( 1 - d );
    if (s=250)
    {
        d==0;
    printf("%d",f);
    }
    else if (s>=250&&s<500)