I have a question in language c.

Asked 1 years ago, Updated 1 years ago, 303 views


#include <stdio.h>

int main() {

    char ch[5];
    char tmp;

    for(int i=0;i<5;i++)
        scanf("%c",&ch[i]);

    for(int i=0;i<5;i++) {
        for(int j=5-i;j<5;j++) {
            printf("%c",ch[j]);
        }

        for(int k=0;k<5-i;k++) {
            printf("%c",ch[k]);
        }

        printf("\n");
    }
    return 0;
}

I did a right shift to move the text to the right, but I can't do a left shift well. Help!

c

2022-12-20 09:14

1 Answers

The loop appears to be output by moving one space to the right, running 5 times through the for(inti=0;i<5;i++) condition.
I think it would be possible if you change the condition of the loop to for(inti=5;i>0;i--).
To explain a little more, the loop that outputs the first line that outputs the input as it is will change from for(intk=0;k<5-i;k++) to and the rest will be output in the same order only.


2022-12-20 09:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.