
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Write a C program to print the message in reverse order using for loop in strings
Here we write a program to reverse the sentence without predefined functions. By using for loop, we can easily print statement in reverse order.
Program 1
#include<stdio.h> int main(){ char stmt[100]; int i; printf("enter the message:
"); for(i=0;i<stmt;i++){ stmt[i]=getchar(); //reading each char from console till enter or newline char is pressend if(stmt[i]=='
') break; } printf("the reverse statement is:
"); for(i--;i>=0;i--) //printing each char in reverse order putchar(stmt[i]); putchar('
'); return 0; }
Output
enter the message: Hi welcome to my world the reverse statement is: dlrow ym ot emoclew iH
Program 2
Here, we will write a C program to reverse a string using strrev library function −
#include<stdio.h> #include<string.h> void main(){ //Declaring two strings// char result[50],string[25]; //Reading string 1 and String 2// printf("Enter String to be reversed : "); gets(string); //Reversing using library function// strrev(string); printf("The reversed string is : "); puts(string); }
Output
Enter String to be reversed : Hi welcome to tutorials Point The reversed string is : tnioP slairotut ot emoclew iH
- Related Articles
- C++ program to concatenate strings in reverse order
- Write a program to print message without using println() method in java?
- How to iterate for loop in reverse order in Swift?
- C program to print multiplication table by using for Loop
- C Program for Print the pattern by using one loop
- Using iterative function print the given number in reverse order in C language
- C program to print name inside heart pattern using for loop.
- Python program to print the elements of an array in reverse order
- C program to write all digits into words using for loop
- How to print the elements in a reverse order from an array in C?
- Write a C program to print ‘ABCD’ repeatedly without using loop, recursion and any control structure
- How to print list values in reverse order using Collections.reverse() in Android?
- Write program to reverse a String without using reverse() method in Java?
- How can I write in order with for loop or while loop?
- Program to print Reverse Floyd’s triangle in C

Advertisements