Write a program that reads 5 words, separated by spaces and then displays them in a line, but in reverse order. The words are stored in an array of strings.


Difficulty level
Video recording
This exercise is mostly suitable for students
#include <stdio.h>
void main()
{
 	/* Declarations */
 	char WORD[5][50]; /* array for the 5 words */
 	int I;           /* counter */
 
	/* Reading words */
 	printf("Enter 5 words, separated by a space :\n");
 	/* After the line feed, scanf read */
 	/* the 5 string all at once. */
 	for (I=0; I<5; I++)
     		scanf("%s", WORD[I]);
 
	/* Display the strings in reverse */
 	for (I=4; I>=0; I--)
    		printf("%s ", WORD[I]);
 	printf("\n");
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Binary tree mirrors