0

How to know the number is integer or not in c++?

21st Jul 2020, 1:20 PM
Nandini B N
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; }
22nd Jul 2020, 5:06 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
Nandini B N welcome use at the rate symbol (@) to mention someone name
22nd Jul 2020, 5:09 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Thank you
21st Jul 2020, 1:36 PM
Nandini B N
+ 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
21st Jul 2020, 4:27 PM
Anthony Maina
Anthony Maina - avatar
+ 1
Tq for your answer
22nd Jul 2020, 1:31 AM
Nandini B N
+ 1
Thank you for your code
22nd Jul 2020, 5:07 PM
Nandini B N
+ 1
Tq for your suggestion 🐰Tiara 🐰 😊
22nd Jul 2020, 5:10 PM
Nandini B N
+ 1
Thank you AteFish
26th Jul 2020, 1:55 AM
Nandini B N