-
Notifications
You must be signed in to change notification settings - Fork 0
/
itr.cpp
61 lines (57 loc) · 1.19 KB
/
itr.cpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//Program to write Integers in Expanded form by Vishruth Codes
#include<iostream>
using namespace std;
//Function to calculate the length of the integer
int lengthofinteger(int n)
{
int count=0;
while(n>0)
{
n=n/10;
count++;
}
return count;
}
//Function to split the integer into digits and store them in array at position corresponding to its power of 10.
void breakdown(int n,int len, int split[])
{
int rem;
for(int i=0;i<len;i++)
{
rem=n%10;
if(n>0)
{
n=n/10;
split[i]=rem;
}
}
}
int main()
{
int n,len;
//Input
cout<<"\nEnter the number: ";
cin>>n;
len=lengthofinteger(n);
cout<<"\nThe length of integer is: "<<len;
int split[len];
breakdown(n,len,&split[0]);
//Output
cout<<"\n\nInteger "<<n<<" expanded form is: ";
for(int i=len-1;i>=0;i--)
{
int mul=1;
for(int j=0;j<i;j++)
{
mul=mul*10;
}
if(i!=0)
{
cout<<split[i]<<"x"<<mul<<" + ";
}
else{
cout<<split[i]<<"x"<<mul;
}
}
return 0;
}