Skip to content

Commit ab66754

Browse files
authored
Merge pull request #492 from AKSHATNEMA/master
Added Rotate_number_by_K.cpp
2 parents 51c9c76 + f097d4c commit ab66754

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Diff for: Rotate_number_by_k.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Rotate digits of a number by K (number of shifts to be made in Number)
2+
3+
#include <iostream>
4+
using namespace std;
5+
6+
7+
int main()
8+
{
9+
cout<<"Enter the number:";
10+
string in;// input number is taken in form of string
11+
cin>>in;
12+
13+
long long int n=in.length(); // stores the length of string number.
14+
cout<<"Enter the number of digits to be shifted:";
15+
long long int k;
16+
cin>>k;
17+
18+
if(k>n) // incase when shifts is greater than the length of number
19+
{
20+
k=k%n;
21+
}
22+
23+
string a=in.substr(0,k);
24+
string b=in.substr(k,n-k);
25+
string ans=b+a;
26+
cout<<"Final number is:"<<ans<<"\n";
27+
28+
return 0;
29+
}
30+

0 commit comments

Comments
 (0)