zoukankan      html  css  js  c++  java
  • 算法习题

    // 打折.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"
    #include<iostream>
    using namespace std;

    int _tmain(int argc, _TCHAR* argv[])
    {
     int a;
     double total;
     cout<<"请输入买衣服的件数";
     cin>>a;
     if(95*a>300)total=(95*a)*0.85;
     else total=95*a;
     cout<<total;
     return 0;
    }


    //// 距离.cpp : 定义控制台应用程序的入口点。


    #include "stdafx.h"
    #include<iostream>
    //#include <math.h> 
    //#include <cmath>
    #include <math.h>//定义数学函数
    using namespace std;


    int _tmain(int argc, _TCHAR* argv[])
    {
     float x1,y1,x2,y2,d;


     cout<<"请输入两个坐标(x1,y1),(x2,y2)";
     cin>>x1>>y1>>x2>>y2;
     d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
     cout<<d;

     return 0;
    }

    ////绝对值.cpp : 定义控制台应用程序的入口点。


    #include "stdafx.h"
    #include<iostream>
    using namespace std;

    int _tmain(int argc, _TCHAR* argv[])
    {
     float a;

     cout<<"请输入一个浮点数";
     cin>>a;

     cout<<(a>0?a:-a);
     return 0;
    }

    // 连续求和.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"
    #include<iostream>
    using namespace std;


    int _tmain(int argc, _TCHAR* argv[])
    {
     int n,sum=0;
     cout<<"请输入一个正整数n:";
     cin>>n;
     while(n)
     {sum+=n--;}
     cout<<"sun="<<sum;
     return 0;
    }

    // 年份.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"
    #include<iostream>
    using namespace std;

    int _tmain(int argc, _TCHAR* argv[])
    {
     int a;
     cout<<"请输入某一年:";
     cin>>a;
     if(a%4==0&&a%100!=0||a%400==0)cout<<"yes";
     else cout<<"no";
     return 0;
    }

    // 偶数.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"
    #include<iostream>
    using namespace std;


    int _tmain(int argc, _TCHAR* argv[])
    {
     int a;
     cout<<"请输入一个整数";
     cin>>a;
     if(a%2==0)cout<<"yes";
     else cout<<"no";
     return 0;
    }

    // 求平均数.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"
    #include<iostream>
    #include<iomanip>
    using namespace std;


    int _tmain(int argc, _TCHAR* argv[])
    {
     int a,b,c;
     float average=0.0;
     cout<<"please enter three numbers:";
     cin>>a>>b>>c;
     average=(a+b+c)/3.0;
     cout<<fixed<<setprecision(3)<<average;
     return 0;
    }

    // 求正弦和余弦.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"
    #include<iostream>
    //#include <math.h> 
    //#include <cmath>
    #include <math.h>//定义数学函数
    using namespace std;


    int _tmain(int argc, _TCHAR* argv[])
    {
     int x;
     double ysin,ycos;
     double pi=3.14;
     cout<<"请输入一个角的度数x:";
     cin>>x;
     ysin=sin((2*pi*x)/360.0);
     ycos=cos((2*pi*x)/360.0);
     cout<<"sin(x)="<<ysin<<endl;
     cout<<"cos(x)="<<ycos<<endl;
     return 0;
    }

    // 三角形.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"
    #include<iostream>
    using namespace std;

    int _tmain(int argc, _TCHAR* argv[])
    {
     int a,b,c;
     
     cout<<"请输入三角形的三边";
     cin>>a>>b>>c;
     if(a+b>c && a+c>b && b+c>a)
      if(a*a==b*b+c*c || b*b==a*a+c*c || c*c==a*a+b*b)
       cout<<"yes";
      else cout<<"no";
     else cout<<"not a triangle";
     
     return 0;
    }

    // 温度转换.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"
    #include<iostream>
    #include<iomanip>
    using namespace std;


    int _tmain(int argc, _TCHAR* argv[])
    {
     float f,c;
     cout<<"请输入华氏温度f:";
     cin>>f;
     c=5*(f-32)/9;
     cout<<fixed<<setprecision(3)<<c;
     return 0;
    }

  • 相关阅读:
    C#无限极分类树-创建-排序-读取 用Asp.Net Core+EF实现之方法二:加入缓存机制
    如何将CKeditor编辑器的上传和thinkphp结合
    在 VisualStudio 给文件起一个带分号的文件名会怎样
    dotnet ConditionalWeakTable 的底层原理
    GitHub 的 Action 判断仅在主仓库才执行脚本
    ASP.NET Core 将文件夹内容输出为压缩包文件方法
    dotnet Microsoft.Recognizers.Text 超强大的自然语言关键词提取库
    dotnet CBB 为什么决定推送 Tag 才能打包
    WPF 通过 InputManager 模拟调度触摸事件
    如何参与 .NET 的开发和设计
  • 原文地址:https://www.cnblogs.com/ljy2013/p/3265093.html
Copyright © 2011-2022 走看看