Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

wirte an LC3 progrmhat wilreadi n anitrar o huracters and storeit n memory. It w

ID: 3914269 • Letter: W

Question

wirte an LC3 progrmhat wilreadi n anitrar o huracters and storeit n memory. It will then rotate the characters one position to the left. It will print the rotated string, and repeat rotating and printing until all the possible rotations have been printed. For example: Enter a string: abcdef Rotated strings: abcdef bcdefa cdefab defabc efabcd fabcde A few implementation requirements: Your program must rotate the strings in memory: that is, change the contents of memory and print the string using PUTS Your program should read input into the string until the end-of-line character (#10) is entered. Your program only needs to process a single input value each time it is run Thanks!

Explanation / Answer

#include<stdio.h>

#include<string.h>//string library to use string inbuilt function like strlen,strcpy here

int main(){

//S is original string that is entered by user

//R is the rotated string that will have the rotated string every time.

char S[10000],R[10000],fchar;

int len,i,l;

printf("Enter the string: ");

scanf("%s[^ ] ",S);//accept the string until line changes

printf("Rotated string : ");

strcpy(R,S);//copy content of string S to string R

//strcpy(destination,source);

len=strlen(R);//stores length of the string R,it can be strlen(S) also because after rotation also length is same

puts(S); //print string with 0 rotation

l=1;//variable that stores the count that rotation must not exceeds the number of length as after that it will again provide the input string

while(l<len){//while loop to check that it terminates if l becomes greater or equal than length

fchar=R[0];//fchar store variable at 0 position so that after shifting one left it never get missed.

for(i=1;i<len;i++){//shifting one by one to previous index

R[i-1]=R[i];

}

R[len-1]=fchar;//after shifting rotated string R will have same value in last index and last-1 index so we will replace last by fchar variable

puts(R);//print rotated string R and changes line

l++;//incrementation

}

printf("End of processing.");

return 0;//return nothing

//you can remove return and change int main to void main

}