forked from YearOfProgramming/2017Challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Go] Challenge 1 (YearOfProgramming#441)
- Loading branch information
1 parent
c202189
commit cdf2b9a
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
``` | ||
go run reverse.go | ||
Enter the string | ||
Get the reverse output | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
//"strings" | ||
) | ||
|
||
func reverseString(str string) string { | ||
var revStr string | ||
for i := len(str) - 1; i >= 0; i-- { | ||
revStr = revStr + string(str[i]) | ||
} | ||
return revStr | ||
|
||
} | ||
|
||
func main() { | ||
var str string | ||
fmt.Println("Enter the string to reverse: ") | ||
fmt.Scanf("%s", &str) | ||
fmt.Println(reverseString(str)) | ||
} |