-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC++ Function Get digits.cpp
More file actions
83 lines (71 loc) · 1.97 KB
/
C++ Function Get digits.cpp
File metadata and controls
83 lines (71 loc) · 1.97 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
[AUTHOR]: Saddam Arbaa
[Email] : <saddamarbaas@gmail.com>
program to find All the digits of any given decimal number */
#include <iostream>
using namespace std;
// function to find digits of decimal number
void findDigitsInDecimal(int N);
// the Driver Code
int main()
{
int n;
// asking user input
cout <<"Enter the number to digits ";
cin >> n;
// call the function and pass the number
findDigitsInDecimal(n);
return 0;// signal to operating system everything works fine
}/** End of Main */
/**
function to find All the digits of any given decimal number*/
void findDigitsInDecimal(int N)
{
// counters
int i,j,siz = 0;
// temp variable
int temp,secodTemp ;
// set both temp equal to given Number
temp = secodTemp = N;
// count the size
while(secodTemp > 0)
{
// get the size of number first
siz++;
secodTemp = secodTemp/10;
}
// by now we know the size let create array
// create array of size size
int aray[siz];
// needed while storing digits to Array
int coun = 0;
while(N > 0)
{
// get each digits and store in temp first then add temp to array list
temp = N % 10;
// add the digit to array
aray[coun] = temp;
//increment count
coun++;
// divide the number by 10 and continue loop
N = N / 10;
}
cout <<endl<<"Array contain flowing before Reverse "<<endl;
for(int i = 0; i <siz ; i++)
cout<<aray[i] <<"\t";
cout << endl;
// let Reverse the Array
for(i = 0,j = siz - 1; i < siz/2; i++)
{
// swap between aray[i] and aray[j]
temp = aray[i];
aray[i] = aray[j];
aray[j] = temp;
// decrement J
j--;
}
cout <<endl<<"Array contain flowing digits After Reverse "<<endl;
for(int i = 0; i <siz ; i++)
cout<<aray[i] <<"\t";
cout << endl;
}/** End of findDigitsInDecimal */