首页 > 代码库 > 张照行 的第三次作业

张照行 的第三次作业

1.

#include<stdio.h>int main(){  printf("**********\n");  printf("*********\n");  printf("********\n");  printf("*******\n");  printf("******\n");  printf("*****\n");  printf("****\n");  printf("***\n");  printf("**\n");  printf("*\n"); }

2.

#include<stdio.h>int main(){  printf("**********\n");  printf("**********\n");  printf("**********\n");  printf("**********\n");  printf("**********\n");  printf("**********\n");  printf("**********\n");  printf("**********\n");  printf("**********\n");  printf("**********\n");}

3.

#include<stdio.h>int main(){  printf("* * * * * * * * * *\n");  printf(" * * * * * * * * *\n");  printf("  * * * * * * * *\n");  printf("   * * * * * * *\n");  printf("    * * * * * *\n");  printf("     * * * * *\n");  printf("      * * * *\n");  printf("       * * *\n");  printf("        * *\n");  printf("         *\n"); }

4.

#include<stdio.h>int main(){    char grade;    printf("请输入等级:");    scanf("%c",&grade);//A,B,C,D,E    switch(grade)    {        caseA:           printf("90~100");            break;//退出switch语句         caseB:           printf("80~89");           break;        caseC:           printf("70~79");           break;         caseD:           printf("60~69");             break;        caseE:           printf("0~59");           break;    } }

5.输入100后输出的结果是37摄氏度

#include<stdio.h>int main(){    int F;    printf("请输入华氏温度:");//因为要求100华氏度的换算所以输入100     scanf("%d",&F);    printf("C=%d摄氏度", 5*(F-32)/9);//输出要为整形所以是%d }

 6.输出的结果是45米

#include<stdio.h>int main(){    int H=100;    int t=3;    int g=10;    printf("一个物体从100米的高空自由落下,它在前3秒内下落的垂直距离\n");    H=0.5*g*t*t;    printf("H=%d米",H);}

7.

#include<stdio.h>int main(){   int a,b,c,d;   printf("请输入一个三位数:"); //这里输入152     scanf("%d",&a);    b=a%10;    c=(a/10)%10;    d=a/100;   printf("三位数%d的个位数字是%d,\n           十位数字是%d,\n           百位数字是%d\n",a,b,c,d);}

8.

#include<stdio.h>#include<math.h>int main(){    double x;    double y;    printf("请输入x的值:");    scanf("%lf",&x);    if(x>=0)        y=sqrt(x);    else        y=pow(x-1,2)+2*x+1/x;    printf("y=f(x)=%.2f",y);    }

9.

#include<stdio.h> #include<math.h>int main() {   int money,year;   double rate,interest,a;   printf("请输入存款金额:");   scanf("%d",&money);    printf("请确认存期:");    scanf("%d",&year);   printf("请确认年利率:");   scanf("%lf",&rate);   a=pow(1+rate,year);   interest=money*(a-1);   printf("存款利息为:%f",interest);}

10.

#include <stdio.h>int main(){   int x;   double y;   printf("请输入本月用电量:");   scanf("%d",&x);   if(x<=50)      y=0.53*x;   else      y=50*0.53+(x-50)*0.58;   printf("本月电费为:%.2lf",y);}

作业问题:为什么我在做第6题的时候中用公式H=0.5*g*t*t;这个语句时,一开始我想用H=1/2*g*t*t的,可是结果就不对,总是输出0,而用0.5又可以了?我前面用的都是int,按理说1/2应该比0.5更为适合,可是为什么就得不出我想要的结果?是跟整型实型有关还是别的什么?我什么的概念没弄清楚?

张照行 的第三次作业