Professional Documents
Culture Documents
Programming Fundamentals
Department:
Software Engineering
Submitted to:
Dr.Madiha Liaqat
Submitted by:
Code:
#include <iostream>
using namespace std;
//main method
int main()
{
//Declaring the variable and initializing sum
long int n,sum=0,r;
cout<<"Enter the Number= ";
cin>>n;
// To calculate the reverse of the number
while(n>0)
{
// The remainder will give the last digit of the
number
r=n%10;
sum=sum*10+r;
n=n/10;
}
n=sum;
//test expression with while loop
while(n>0)
{
// Extract the first digit of the reversed number
r=n%10;
// Match it with switch case
switch(r)
{
case 1: // expression is equal to constant one
cout<<"one "; // code to be executed
break; // break statement end
case 2: // expression is equal to constant two
cout<<"two ";
break; //break statement end
case 3: // code to be executed
cout<<"three "; // expression is equal to
constant three
break; //break statement end
case 4: // code to be executed
cout<<"four "; // expression is equal to
constant four
break; //break statement end
case 5: // expression is equal to constant
five
cout<<"five "; // code to be executed
break; //break statement end
case 6: // expression is equal to constant
six
cout<<"six "; // code to be executed
break; //break statement end
case 7: // expression is equal to constant
seven
cout<<"seven "; // code to be executed
break; //break statement end
case 8: // expression is equal to constant
eight
cout<<"eight "; // code to be executed
break; //break statement end
case 9: // expression is equal to constant
nine
cout<<"nine "; // code to be executed
break;//break statement end
case 0: // expression is equal to constant zero
cout<<"zero "; // code to be executed
break; //break statement end
default:
// Created by (20-SE-64)
cout<<"tttt ";
break;//break statement end
}
// Divide the number by 10 to get the next
number
n=n/10;
}
}