We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 51c9c76 + f097d4c commit ab66754Copy full SHA for ab66754
Rotate_number_by_k.cpp
@@ -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