132k views
3 votes
Write a program named as reverse.c that reads a message, then prints the reversal of the message. The output of the program should look like t

User Darshanie
by
5.4k points

1 Answer

3 votes

Answer:

Written in C:

#include <stdio.h>

#include <strings.h>

int main(){

char userinput[100];

printf("Enter a message: ");

scanf("%s",&userinput);

int lent = strlen(userinput);

for (int i=lent-1; i>=0; i--)

printf("%c",userinput[i]);

return 0;

}

Step-by-step explanation:

This line declares a string variable

char userinput[100];

This line prompts user for input

printf("Enter a message: ");

This line gets user input

scanf("%s",&userinput);

This line calculates the length of user input

int lent = strlen(userinput);

This iterates through the characters of user input

for (int i=lent-1; i>=0; i--)

This prints the characters in reverse

printf("%c",userinput[i]);

User Aaronsteers
by
5.6k points