FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp/F20RecursionAssignment/StringToInteger.cpp at main · roydevashish/cpp · GitHub
roydevashish
/
cpp
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp
/
F20RecursionAssignment
/
StringToInteger.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (42 loc) · 1.04 KB
Breadcrumbs
cpp
/
F20RecursionAssignment
/
StringToInteger.cpp
Copy path
File metadata and controls
56 lines (42 loc) · 1.04 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
Title: String to Integer
Problem statement
Write a recursive function to convert a given string into the number it represents. That is input
will be a numeric string that contains only numbers, you need to convert the string into
corresponding integer and return the answer.
Detailed explanation ( Input/output format, Notes, Images )
Input format :
Numeric string S (string, Eg. "1234")
Output format :
Corresponding integer N (int, Eg. 1234)
Constraints :
0 < |S| <= 9
where |S| represents length of string S.
Sample Input 1 :
00001231
Sample Output 1 :
1231
Sample Input 2 :
12567
Sample Output 2 :
12567
*/
#
include
<
iostream
>
#
include
<
math.h
>
using
namespace
std
;
int
StringToNumber
(
char
input[]) {
if
(input[
0
] ==
'
\0
'
) {
return
0
;
}
int
smallOutput =
StringToNumber
(&input[
1
]);
int
length =
0
;
while
(input[length] !=
'
\0
'
) {
length++;
}
return
((
int
)input[
0
]-
48
) *
pow
(
10
, length-
1
) + smallOutput;
}
int
main
() {
char
input[
50
];
cin >> input;
cout <<
StringToNumber
(input) << endl;
}
Back
|
FazBrowse Home
|
New Git URL