Skip to main content

Checking number of digits in C++ using if else conditions

#include<iostream>
using namespace std;
int main()
{
int x=0;
int i;
int y;
int z;
int a;
int d;
int c;
int b;
cout<<"enter a four digit number:";
cin>>x;
a=x%10;
y=x/10;
b=y%10;
z=y/10;
c=z%10;
d=z/10;
if(d>9)
{
cout<<"number is not 4 digit";
}
else if(d==0)
{
cout<<"number is not 4 digit";
}
else
{
cout<<d<<endl;
cout<<c<<endl;
cout<<b<<endl;
cout<<a<<endl;
}
return 0;
}
************************
output:

Comments

Popular posts from this blog

Area Calculation By ImageJ

  Area Calculation By ImageJ      Open the Software      File => Open       Zoom in the Image and select the straight line        Mark the small line on graph and go to analyse => set scale      Set known distance 01, unit cm and click ok       Go to free hand and cover the area you want to calculate       Then press (ctrl + m) repeat the process for 3 time       After that go to the result and summarize 

Weight conversion program using functions in c++

#include<iostream> using namespace std; int num(int n) { cout<<"num of chocolate:"; cin>>n; return n; } int ounce(int a) { cout<<"weight in ounce:"; cin>>a; return a; } int pound(int b) { cout<<"weight in pound:"; cin>>b; return b; } int main () { int n, a, b; char choice; cout<<"enter choice 'o' for ounce and 'p' for pounds:"; cin>>choice; int x, y, z; x = num(n); y = ounce(a); z = pound(b); if (choice == 'o') {cout<<"total weight in ounce:"<<x*y;} if (choice == 'p') {cout<<"total weight in pounds:"<<x*z;} return 0; } ************************** Output:

Call for Applications: PhD Program in "Information Engineering and Computer Science"

The University of Trento (Italy) invites applications for admission to the PhD Program in Information Engineering and Computer Science for the academic year 2025/2026. Fields of Research: Computer Science Electronics Electromagnetic Fields Telecommunications Economic-Management Engineering Information Processing Systems Electronic and Computer Bioengineering Opportunities Available: Total Positions: 34 Funded Scholarships: 32 Positions without Scholarship: 2 Reserved Positions for Foreign Scholarship Holders: 1 International mobility is required – candidates from Africa, Europe, Oceania, North America, South America, Asia, and other regions are welcome to apply! پی ایچ ڈی پروگرام "انفارمیشن انجینئرنگ اور سائنس" (41 واں سائیکل - پہلی کال) کے لیے درخواستوں کا اعلان یونیورسٹی آف ٹرینٹو (اٹلی) میں "انفارمیشن انجینئرنگ اور کمپیوٹر سائنس" کے پی ایچ ڈی پروگرام (اکیڈمک سال 2025/2026، پہلی کال) میں داخلے کے لیے درخواستیں طلب کی جا رہی ہیں۔ ریسرچ کا میدان: کمپیوٹر سائنس الیک...