首页 > 代码库 > 第三次作业

第三次作业

十行倒三角形

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

十行三角形

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

十行矩形

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

2-2-4 分段函数[2]

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

2-2-1 分段函数[1]

#include<stdio.h>int main(){   int x;   double y;   printf("请输出x的值");   scanf("%d",&x);   if (x==0)           y=0;    else        y=1/(double)x;        printf("%f",y);}

2-1-7 整数152的各位数字

#include<stdio.h>int main(){int c=152;int gewei,shiwei,baiwei;gewei=c%10;shiwei=c/10%10;baiwei=c/100%10;printf("百位=%d, 十位=%d, 个位=%d",baiwei,shiwei,gewei);}

2-2-3 计算存款利息

#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-money;   printf("利息为:%f\n",interest);   return 0;}

阶梯电费

#include <stdio.h>int main(){   int c ;   double f;   scanf("%d",&c);   if(c<=50)     {f=0.53*c;}   else     {f=50*0.53+(c-50)*0.05;}   printf("费用为:%lf",f);   return 0;}

2-1-3 计算物体自由下落的距离

#include<stdio.h>int main()    double height;    int t=3;    height=0.5*10*t*t;    printf("height=%.2f\n",height);    return 0;} 

温度

#include<stdio.h>int main() {    double F;    printf("请输入华氏温度:\n");    scanf("%lf", &F);    printf("C = %0.2lf\n", 5*(F-32)/9);    return 0;}

 

第三次作业