首页 > 编程语言 >智能计算程序

智能计算程序

时间:2024-08-07 22:57:32浏览次数:16  
标签:&& aa cout b% int 程序 智能 计算 year%

闲来无事,又敲一堆代码,嘻嘻

还想看什么,留言哦! 

#include<bits/stdc++.h>
using namespace std;
int main()
{
	cout<<"智能计算程序"<<endl;
	
	
	
	//1
	int ao;
	char s=2;
	while(s==2)
	{ 
	cout<<endl;
	cout<<"按1判断倍数"<<endl;
	cout<<"按2计算面积"<<endl;
	cout<<"按3求平方"<<endl;
	cout<<"按4年份计算"<<endl;
	cout<<"按5计算ASCII码"<<endl;
    cout<<"按6四则运算"<<endl;
    cout<<"按7判断是否是质数"<<endl;
    cout<<"按8判断最大公约数"<<endl;
    cout<<"按9智能计算器"<<endl;
	cin>>ao;
	//判断倍数
	if(ao==1)
	{
	int a;
	cout<<"判断倍数"<<endl;
	cout<<endl;
	cout<<"按1判断是否是3的倍数"<<endl;
	cout<<"按2判断是否是5的倍数"<<endl;
	cout<<"按3判断是否是6的倍数"<<endl;
	cout<<"按4判断是否是7的倍数"<<endl;
	cout<<"按5判断是否是8的倍数"<<endl;
	cout<<"按6判断是否是9的倍数"<<endl;
	cin>>a;
	if(a==1)
	{
		int x;
		cout<<"输入一个数" <<endl;
		cin>>x;
		if(x%3==0)
		{
			cout<<"YES"<<endl;
			cout<<"结束";
		}
		else
		{
			cout<<"NO"<<endl;
			cout<<"结束";
		}
	}
	if(a==2)
	{
		int y;
		cout<<"输入一个数" <<endl;
		cin>>y;
		if(y%5==0)
		{
			cout<<"YES"<<endl;
			cout<<"结束"; 
		}
		else
		{
			cout<<"NO"<<endl;
			cout<<"结束";
		}
	}
	
	if(a==3)
	{
		int z;
		cout<<"输入一个数" <<endl;
		cin>>z;
		if(z%6==0)
		{
			cout<<"YES"<<endl;
			cout<<"结束";
		}
		else
		{
			cout<<"NO"<<endl;
			cout<<"结束";
		}
	}
		if(a==4)
	{
		int a;
		cout<<"输入一个数" <<endl;
		cin>>a;
		if(a%7==0)
		{
			cout<<"YES"<<endl;
			cout<<"结束";
		}
		else
		{
			cout<<"NO"<<endl;
			cout<<"结束";
		}
	}
		if(a==5)
	{
		int b;
		cout<<"输入一个数" <<endl;
		cin>>b;
		if(b%8==0)
		{
			cout<<"YES"<<endl;
			cout<<"结束";
		}
		else
		{
			cout<<"NO"<<endl;
			cout<<"结束";
		}
	}
		if(a==6)
	{
		int c;
		cout<<"输入一个数" <<endl;
		cin>>c;
		if(c%9==0)
		{
			cout<<"YES"<<endl;
			cout<<"结束";
		}
		else
		{
			cout<<"NO"<<endl;
			cout<<"结束";
		}
	}
    }
    	//计算面积
		if(ao==2)
	{
		int aa;
		cout<<"计算面积"<<endl;
		cout<<endl;
		cout<<"按1计算正方形的面积"<<endl;
		cout<<"按2计算长方形的面积"<<endl;
		cout<<"按3计算三角形的面积"<<endl;
		cout<<"按4计算梯形的面积"<<endl;
		cout<<"按5计算平行四边形的面积"<<endl;
		cin>>aa;
	if(aa==1)
	{
		int xa;
		cout<<"输入1个数(边长)" <<endl;
		cin>>xa;
	    cout<<xa*xa<<endl;
		cout<<"结束";
	}
		if(aa==2)
	{
		int ya,ya2;
		cout<<"输入2个数(长,宽)" <<endl;
		cin>>ya>>ya2;
	    cout<<ya*ya2<<endl;
		cout<<"结束";
	}
	
	if(aa==3)
	{
		int za,za2;
		cout<<"输入2个数(高,底)" <<endl;
		cin>>za>>za2;
	    cout<<za*za2/2<<endl;
		cout<<"结束";
	}
	if(aa==4)
	{
		int sa,sa2,sa3;
		cout<<"输入3个数(上底,下底,高)" <<endl;
		cin>>sa>>sa2>>sa3;
	    cout<<(sa+sa2)*sa3/2<<endl;
		cout<<"结束";
	}
	if(aa==5)
	{
		int aaa,aaa2;  
		cout<<"输入2个数(高,底)" <<endl;
		cin>>aaa>>aaa2;
	    cout<<aaa*aaa2<<endl;
		cout<<"结束";
	}
	} 
	//求平方
	if(ao==3)
	{
		int aa5;
		cout<<"求平方"<<endl;
		cout<<endl;
		cout<<"按1计算平方"<<endl;
		cout<<"按2计算平方根"<<endl;
		cin>>aa5;
		if(aa5==1)
		{ 
		cout<<"输入一个数"<<endl;
		int aal;
		cin>>aal;
		cout<<aal*aal<<endl;
		cout<<"结束";
	    }
	    if(aa5==2)
		{ 
		cout<<"输入一个数"<<endl;
		double aa22;
		cin>>aa22;
		 printf("%lf",sqrt(aa22) );
		cout<<"结束";
	    }
    }
   //年份计算
    	if(ao==4)
	{
		cout<<"年份计算"<<endl;
		cout<<endl;
		cout<<"判断闰年"<<endl;
		cout<<"输入年份"<<endl;
		int year;
		cin>>year;
		if(year%4==0&&year%100!=0||year%400==0)
		{
			cout<<year<<"是闰年"<<endl;
		}
		else
		{
			cout<<year<<"不是闰年"<<endl;
		}
		cout<<"结束";
	   
    }
    //计算ASCII码  	
		if(ao==5)
	{
		cout<<"计算ASCII码"<<endl;
		cout<<endl;
		cout<<"输入一个字母"<<endl;
		char ascll;
		cin>>ascll;
		cout<<ascll<<"的ASCLL码是"<<(int)ascll<<endl;  
		cout<<"结束";
    }
    //四则运算
    	if(ao==6)
	{
		cout<<"四则运算"<<endl;
		cout<<endl;
		cout<<"输入两个数 一个运算符(+,-,*,/)"<<endl;
		char op;
		double  num1,num2;
		cin>>num1>>num2>>op;
		switch(op)
		{
			case'+':cout<<num1<<op<<num2<<"="<<num1+num2<<endl;break;
		    case'-':cout<<num1<<op<<num2<<"="<<num1-num2<<endl;break;
		    case'*':cout<<num1<<op<<num2<<"="<<num1*num2<<endl;break;
		   	case'/':if(num2!=0)cout<<num1<<op<<num2<<"="<<num1/num2<<endl;else cout<<"这两个数相除等于零"<<endl;break;
		    default:cout<<op<<"不是运算符"<<" "<<"+,-,*,/才是运算符"<<endl; 
		}  
		cout<<"结束";
    }
    //判断是否是质数
    if(ao==7)
	{
		cout<<"判断是否是质数"<<endl;
		cout<<endl;
		cout<<"输入一个数"<<endl;
		int i,n;
		cin>>n;
		i=2;
		while(n%i!=0 && i<n-1)
	
			i++;
			if(i>n-1)cout<<n<<"是质数"<<endl;
			else cout<<n<<"不是质数"<<endl;
			cout<<"结束";
    }
    //判断最大公约数
     if(ao==8)
	{
		cout<<"判断最大公约数"<<endl;
		cout<<endl;
		cout<<"输入两个数"<<endl;
		int a,b,g;
		cin>>a>>b;
		g=a>b?b:a;
		while (g>1 && (a%g!=0||b%g!=0))
		g--;
	    cout<<a<<"和"<<b<<"的最大公约数是"<<g<<endl;
	    cout<<"结束";
	
    }
    //智能计算器
	if(ao=9) 
    cout<<"智能计算器"<<endl;
	cout<<"输入算式"<<endl;
	cout<<"示例:1+2"<<endl;
	float n1,n2;
	char p;
		cin>>n1>>p>>n2;
		switch(p)
		{
			case'+':cout<<'='<<n1+n2<<endl;break;
			case'-':cout<<'='<<n1-n2<<endl;break;
			case'*':cout<<'='<<n1*n2<<endl;break;
			case'/':if(n2!=0)cout<<'='<<n1/n2<<endl;else cout<<"除数不可以为0"<<endl;break;
			default:cout<<"无效算式"<<endl;
		}
	cout<<"你要结束吗?结束按1,不按2"<<endl;
		cin>>s;
		if(s=1) break;
		if(s=2);  
	}
    
	
	
	 
	return 0;
}

标签:&&,aa,cout,b%,int,程序,智能,计算,year%
From: https://blog.csdn.net/renhongxu003008/article/details/140968501

相关文章