0
How to know the number is integer or not in c++?
11 Respostas
+ 4
See this here is program for int and float you can also check for string and char
#include<stdio.h>
#include<string.h>
int main()
{
char number[10];
int flag=0;
int length ;
printf("Enter a number \n");
scanf("%s",number);
length=strlen(number);
while(length--)
{
if(number[length]=='.')
{
flag=1;
break;
}
}
if(flag)
printf("Floating point\n");
else
printf("Integer\n");
return 0;
}
+ 3
Nandini B N welcome use at the rate symbol (@) to mention someone name
+ 1
Thank you
+ 1
You can also use the is_same type predicate
I.e.
int a; char b; float c;
is_same<decltype(a),int>::value;//true
is_same<decltype(b),int>::value;//false
is_same<decltype(c),int>::value;//false
+ 1
Tq for your answer
+ 1
Thank you for your code
+ 1
Tq for your suggestion 🐰Tiara 🐰 😊
+ 1
Thank you AteFish