• 作业2 习题2


    /*计算和,差,商,积*/
    #include<stdio.h> int main(void) { double num1,num2; char op; printf("Type in an expression:"); scanf("%lf%c%lf",&num1,&op,&num2); switch(op){ case'+': printf("=%.2f ",num1+num2); break; case'-': printf("=%.2f ",num1-num2); break; case'*': printf("=%.2f ",num1*num2); break; case'/': printf("=%.2f ",num1/num2); break; default: printf("SORRY,sorry "); break; } return 0; }

    /*输入x,n,计算x^n*/
    #include<stdio.h> int main(void) { int i,n; double sum, x; printf("enter x,n:"); scanf("%lf%d", &x, &n); sum= 1; for(i = 1; i <= n; i++) { sum= sum * x; printf("%.2f ", sum); } return 0; }

    /*计算i^2+1/i的和*/
    #include <stdio.h> int main(void) { int i,m,n; double sum; printf("enter m and n:"); scanf("%d%d",&m,&n); sum=0; /*赋予sum的初值为0*/
    for(i=m;i<=n;i++){ sum=sum+i*i+1.0/i; } printf("sum=%.2f ",sum); return 0; }

    /*计算1-2/3+3/5-4/7+5/9-6/11+...的n项之和*/
    #include<stdio.h> #include<math.h> int main(void) { int i,n,fenzi,fenmu,flag; double item,sum; printf("enter n:"); scanf("%d",&n); flag=1; /*赋予初值*/
    fenzi
    =1; fenmu=1; sum=0; for(i=1;i<=n;i++){ item=1.0*flag*fenzi/fenmu; sum=sum+item; fenzi=fenzi+1; fenmu=fenmu+2; flag=-flag; } printf("sum=%.2f ",sum); return 0; }

    /*输出“还款年限-月还款表”*/
    #include <stdio.h> #include <math.h> /*程序中调用数学函数*/
    int main(void) { int year; double loan,money,my,rate; scanf("%Lf",&loan); scanf("%Lf",&rate); printf("enter year money "); for(year=5;year<=30;year++){ my=pow(1+rate,12*year); money=loan*rate*my/(my-1); printf("year=%d money=%.0f ",year,money); } return 0; }

    /*调用pow函数求幂*/
    #include<stdio.h> #include<math.h> /*调用数学函数*/
    int main(void) { int n,i; double power,sum; printf("enter n:"); scanf("%d",&n); sum=0; for(i=1;i<=n;i++){ power=pow(2,i); /*调用幂函数pow(2,i)计算2的i次方*/
    sum
    =sum+power; } printf("sum=%.2f ",sum); return 0; }
  • 相关阅读:
    [CVPR2017]Online Video Object Segmentation via Convolutional Trident Network
    [CVPR2018]Context-aware Deep Feature Compression for High-speed Visual Tracking
    光栅图形学(二):圆弧的扫描转换算法
    光栅图形学(一):直线段的扫描转换算法
    Vector使用
    STL源码剖析 — 空间配置器(allocator)
    C++ traits技术浅谈
    OpenCv 2.4.9 (二) 核心函数
    vs2017 android demo
    asp.net webapi 自托管插件式服务
  • 原文地址:https://www.cnblogs.com/zy1235/p/3397984.html
Copyright © 2020-2023  润新知