c++,判断闰年 ,判断数的类型,判断数字 ,判断整数的位数,判断字符类型.

1,判断闰年

#include<iostream>

using namespace std;
int main()
 {  
   int year;
   cin>>year;
   if(year%4==0&&year%100!=0||year%400==0)
    cout<<"IsLeapYear"<<endl;
   else
    cout<<"NotLeapYear"<<endl;
 	return 0;
 }

2,判断数的类型

#include<iostream>
using namespace std;
 int main()
 {
    double i;
    cin>>i;
    if(i>1e-10)
    {
    	if(int(i)==i)
    	      cout<<"positive integer"<<endl;
    	else
    	       cout<<"positive real"<<endl;
	}
    else if(i<-1e-10)
    {
    	if(int(i)==i)
    	     cout<<"negative integer"<<endl;
        else
        cout<<"negative real"<<endl;
	}
	else
        cout<<"zero"<<endl;
 	return 0;
 }

3,判断数字 

#include<iostream>

using namespace std;
int main()
 {  
   char c;
   cin>>c;
   if(c>='0'&&c<='9')
    cout<<1;
   else
    cout<<0;
 	return 0;
 }

4,判断整数的位数

#include <iostream>
using namespace std;
int main()
{
unsigned int count = 1;
int n;
cin>> n;
for (int i=0;i<n&&n>= 10; ++i) 
{
n=n/10;
++ count;
}
cout << count << endl;
return 0;
}

5,判断字符类型

#include<iostream>
using namespace std;
 int main()
 {
    char ch;
    ch=cin.get();
    if(ch>='A'&&ch<='Z')
         cout<<"1"<<endl;
    else if(ch>='a'&&ch<='z')
         cout<<"2"<<endl;
    else if(ch>='0'&&ch<='9')
         cout<<"0"<<endl;
    else
         cout<<"-1"<<endl;
 	return 0;
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值