Chapter 4:
Input And Output
Programming Exercise
Problem # 12:
Write a program that inputs 3-digit number and displays its digits in speprate three lines. For example if the user enters 123, the program displays the output as follows:
1
2
3
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int n, a, b, c;
cout<<"Enter a 3-digit number : ";
cin>>n;
a = n % 10;
n = n / 10;
b = n % 10;
n = n / 10;
c = n % 10;
cout<<c<<endl<<b<<endl<<a<<endl;
return 0;
}
#include<conio.h>
using namespace std;
int main()
{
int n, a, b, c;
cout<<"Enter a 3-digit number : ";
cin>>n;
a = n % 10;
n = n / 10;
b = n % 10;
n = n / 10;
c = n % 10;
cout<<c<<endl<<b<<endl<<a<<endl;
return 0;
}
Code Screenshot:
Output:
Let me know in the comment section if you have any question.
Previous Post:
11. Program that inputs temperature from the user in Farenheit and converts it into Celsius degree.
kia ap ka koi youtube chanel ha?
ReplyDelete