1.输入任意三个整数并输出其中最大的数

// c.cpp : 定义控制台应用程序的入口点。
#include "stdafx.h"
#include <iostream>
using namespace std;
int max_num(int x, int y, int z){
    int max;
    max = x>y? x:y;
    max = max>z? max:z;
    return max;
}

int main(){
    int a, b, c;
    cout <<"please inpuut three numbers!" <<endl;
    cin >>a >>b >>c;
    cout <<"the maxiest number is " <<max_num(a, b, c) <<endl;
    return 0;
}
=====
input: -1 -2 -3
-----
output: -1

2.

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

int prime(int x){
    int i;
    for(i = 2; i < x/2; i++)
        if(x%i == 0)   break;
    if(i >= x/2)   return x;
    else return 0;
}

int main(){
    int a, i;
    for(a = 100,i = 1;a <= 200;a++){
        if(prime(a)){
            cout <<prime(a) <<" ";
            if(i%5 == 0) cout <<endl;
            i++;
        }
    }
    return 0;
}

3.

// c.cpp : 定义控制台应用程序的入口点。
#include "stdafx.h"
#include <iostream>
using namespace std;

int Hermite(int x, int n){
    int p = 1;
    if(n == 0) p = 0;
    else if(n == 1) p = 2*x;
    else if(n > 1) p = 2*x*Hermite(x, n-1)-2*(n-1)*Hermite(x, n-2);
    return p;
}

int main(){
    int x, n;
    cout <<"please input the x and n: ";
    cin >>x >>n;
    if(n == 0) cout<<1;
    else if(n == 1) cout <<2*x <<endl;
    else if(n > 1) cout <<Hermite(x, n) <<endl;
    else cout <<"inputing is illegent!" <<endl;
    return 0;
}

https://blog.csdn.net/liyuanbhu/article/details/62904994

Last modification:November 10th, 2020 at 06:04 pm
小编饿得写不动了,请给小编加鸡腿