Program to find the total number of digits in C, C Plus Plus (C++, CPP) with flowchart
Program to find the total number of digits in C, C Plus Plus (C++, CPP) with flowchart
Let’s see the “Program to find the total number of digits in C, C Plus Plus (C++, CPP) with flowchart”.
Flowchart to find the total number of digits
Let’s see the flowchart to find the total number of digits.
Program to find the total number of digits in C++
Let’s see the “Program to find the total number of digits in C++”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include<iostream> #include<conio.h> using namespace std; int main() { int num; int a=0; cout<<"Please Enter any number : "; cin>>num; while(num>0) { num=num/10; a++; } cout<<"Number of digits in given number is: "<<a; getche(); } |
Output
Program to find the total number of digits using else if statement in C++
Let’s see the “Program to find the total number of digits using else if statement in C++”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include<iostream> using namespace std; int main() { int GivenNumber; cout<<"Enter the Numbers"<<endl; cin>>GivenNumber; if(GivenNumber<=9) { cout<<"total number of digits are="<<"1"; } else if(GivenNumber>9&&GivenNumber<100) { cout<<"total numbers of digits=2"; } else if(GivenNumber>99&&GivenNumber<1000) { cout<<"total numbers of digits=3"; } else if(GivenNumber>999&&GivenNumber<10000) { cout<<"total numbers of digits=4"; } else if(GivenNumber>9999&&GivenNumber<100000) { cout<<"total number of digits=5"; } else { cout<<"Please Enter The Number Less Than 100000"; } } |
Program to find the total number of digits (Except 0) using Switch statement in C++
Let’s see the “Program to find the total number of digits (Except 0) using switch statement in C++”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include<iostream> using namespace std; int main() { int number; int digits=0; int p=1; cout<<"Input a large number"<<endl; cin>> number; for(int i=0; i<p; i++) switch(number) { case 0: { p=0; break; } default: { number=number/10; digits++; p++; } } cout<<"the total numbers of digits inside given number are = "<<digits<<endl; } |
Program to find the total number of digits using Array in C++
Let’s see the “Program to find the total number of digits using arrays in C++”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include<iostream> using namespace std; int main() { int array[100]; int number, digits=0; p=0; cout<<"Input a large number"<<endl; cin>>number; do { array[p]=number/10; number=array[p]; digits++; p++; } while(number>0) ; cout<<"the total numbers of digits inside given number are = "<<digits<<endl; } |
Program to find the total number of digits using a do-while loop in C++
Let’s see the “Program to find the total number of digits using a do-while loop in C++”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include<iostream> using namespace std; int main() { int number; int TotalDigits=0; cout<<"Input a large number"<<endl; cin>>number; do { number=number/10; TotalDigits++; } while(number>0); cout<<"the total numbers of TotalDigits inside given number are = "<<TotalDigits<<endl; } |
Program to find the total number of digits using a for loop in C++
Let’s see the “Program to find the total number of digits using a for loop in C++”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include<iostream> using namespace std; int main() { int number; int digits=0; cout<<"Input a large number"<<endl; cin>>number; for(;number>0; digits++) { number=number/10; } cout<<"the total numbers of digits inside given number are = "<<digits<<endl; } |
Program to find the total number of digits using a user define a function in C++
Let’s see the “Program to find the total number of digits using a user define a function in C++”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include<iostream> using namespace std; int totalDigits(int); int main() { int number; cout<<"Input a large number"<<endl; cin>>number; cout<<"the totalDigits numbers of digits inside given number are = "<<totalDigits(number)<<endl; } int totalDigits(int number) { int digits=0; for(;number>0;) { number=number/10; digits++; } return digits; } |
Program to find the total number of digits using a while loop in C++
Let’s see the “Program to find the total number of digits using a while loop in C++”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include<iostream> using namespace std; int main() { long int number; int totalDigits=0; cout<<"Input a large number"<<endl; cin>>number; while(number>0) { number=number/10; totalDigits++; } cout<<"the total numbers of totalDigits inside given number are = "<<totalDigits<<endl; } |
Program to find the total number of digits in C
Let’s see the “Program to find the total number of digits in C”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include<stdio.h> #include<conio.h> int main() { int num; int a=0; printf("Please Enter any number : "); scanf("%d" , &num); while(num>0) { num=num/10; a++; } printf("Number of digits in given number is: %d", a); getche(); } |
Output