+ 2

i had a test for u guys. example : input:253 output: 2 5 3

29th Oct 2016, 5:39 AM
Farhan Sindy
Farhan Sindy - avatar
7 Answers
+ 3
#include <iostream> using namespace std; int a=253, x,y,z; int main() { x=a/100; y= (a-x*100)/10; z= (a-x*100-y*10); cout << x << endl; cout << y << endl; cout << z << endl; return 0; }
29th Oct 2016, 6:13 AM
Kirill
+ 1
One of lot of ways: string s; getline(cin, s); for(char c: s) cout << c << endl;
29th Oct 2016, 5:50 AM
Daniel Oravec
Daniel Oravec - avatar
+ 1
how abt input :253 output : 4 25 9 4+25+9=38
29th Oct 2016, 5:58 AM
Farhan Sindy
Farhan Sindy - avatar
+ 1
get the number from user convert it into reverse and then print the remainders by dividing the reverse by 10,and modifying the reverse no. into a 2 digit no. by eliminating the last digit
29th Oct 2016, 6:07 AM
Saptarshi Saha
Saptarshi Saha - avatar
+ 1
your answer: #include <iostream> using namespace std; int main() { int i; cout<<"enter a number: \n"; cin>>i; void rev(int& x); rev(i); while(i!=0) { cout<<i%10<<endl; i=i/10; } return 0; } void rev(int& x) { int s=0,r; while(x!=0) { r=x%10; x=x/10; s=s*10+r; } x=s; }
29th Oct 2016, 6:27 AM
Saptarshi Saha
Saptarshi Saha - avatar
0
include "iostream.h" void main () { Int a[2]; cout<<" input number";cin>>a[2]: for(int b=0; b<=2 ; b++;) {cout<<a[b] <<endl; } }
29th Oct 2016, 6:06 AM
F.Muharram
0
One of ways to solve second case: string s; int sum = 0; getline(cin, s); for(char c: s) { sum += ((c - '0') * (c - '0')); cout << ((c - '0') * (c - '0')) << endl; } cout << (s[0] - '0') * (s[0] - '0'); for(int i = 1; i < s.length(); i++) cout << '+' << ((s[i] - '0') * (s[i] - '0')); cout << '=' << sum << endl;
29th Oct 2016, 6:30 AM
Daniel Oravec
Daniel Oravec - avatar