w3resource logo


C Programming Exercises

C Exercises: Print characters in a reverse way

Secondary Nav

C Basic Declarations and Expressions : Exercise-4 with Solution

Write a C program to print the following characters in a reverse way.
Test Characters : 'X', 'M', 'L'
Expected Output :

The reverse of XML is LMX

C Code:

#include <stdio.h> 
 int main() 
 {
    char char1 = 'X';
    char char2 = 'M';
    char char3 = 'L';

	printf("%The reverse of %c%c%c is %c%c%c\n",
		char1, char2, char3,
		char3, char2, char1);

	return(0);
}

Solution

#include <stdio.h> 
  
  int main()  
  {
   char char1 = 'X';
   char char2 = 'M';
   char char3 = 'L';
   
  printf("The reverse of %c%c%c is %c%c%c\n",
		char1, char2, char3,
		char3, char2, char1);
	return 0;
  }

Improve this sample solution and post your code through Disqus.



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

PHP: Loop

JavaScript: Delete duplicates in an array

Oracle: Round the number