zoukankan      html  css  js  c++  java
  • 作业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; }
  • 相关阅读:
    (转)基于MapWinGis开发探索(一)
    ArcGIS Server REST API开发相关新词汇
    自写地图全图功能
    向远程目录写数据
    GetUpperBound方法
    监控安装教程
    办公室局域网打印机共享设置
    电脑Bois中usb模式启动热键
    SQL SERVER 2005无法远程连接
    用网线直接把打印机连入网络的问题
  • 原文地址:https://www.cnblogs.com/zy1235/p/3397984.html
Copyright © 2011-2022 走看看