1.将输入的分钟数转化为某某小时某某分钟
例如,输入90,输出1小时 30分钟
#include <iostream>
using namespace std;
int main()
{
int minute,hour;
cout<<"请输入分钟数:";
cin>>minute;
hour=minute/60;
minute=minute-hour*60;
if(hour==0){
cout<<minute<<"分钟";
}
else{
cout<<hour<<"小时 "<<minute<<"分钟";
}
return 0;
}
2.求圆形,正方形,矩形的面积
#include <iostream>
using namespace std ;
const float PI = 3.1416;
int main()
{
int iType;
float radius, len, width, area;
cout << "图形的类型为?(1-圆形 2-长方形 3-正方形):"; cin >> iType;
switch(iType)
{
case 1:
cout << "圆的半径为:";
cin >> radius;
area = PI * radius * radius;
break;
case 2:
cout << "矩形的长为:";
cin >> len;
cout << "矩形的宽为:";
cin >> width;
area = len * width;
break;
case 3:
cout << "正方形的边长为:";
cin >> len; area = len * len;
break;
default:
cout << "不是合法的输入!"<<endl;
break;
}
cout<<"面积"<<area<<endl;
return 0;
}
3.输入小写字母,输出大写字母。输入大写字母,输出小写字母
#include<iostream>
using namespace std;
int main()
{
char a;
cin>>a;
if(a>='a' && a<='z')
{
a = a-32;
}
else if(a>='A' && a<='Z')
{
a= a+32;
}
cout<<a;
return 0;
}
4.输入三个实数,求其中的最大的数,并输出
#include <iostream>
using namespace std;
int main()
{
float a,b,c;
cout<<"请分别输入三个实数,中间使用空格隔开:";
cin>>a>>b>>c;
if(a>=b&&a>=c){
cout<<a;
}
else if(b>=a&&b>=c)
{
cout<<b;
}
else{
cout<<c;
}
return 0;
}
5.关于素数
#include <iostream>
using namespace std;
int main()
{
int L,R,z,c=0;
cin>>L>>R;
for(int x=L;x<=R&&x>=L;){
for(int h=2;h<x;){
if(x%h==0){
z=0;}
h++;
}
if(z!=0){
c++;
}
x++;
z=1;
}
cout<<c;
return 0;
}
评论(0)