c program to reverse string

list of programs for reversing string: C program to reverse string using strrev function, C program to reverse string without strrev function i.e. C program to reverse string using arrays, C program to reverse string using pointers, C program to reverse string using recursion,  C program to reverse string using stacks.

c program to reverse string using pointers
write a c program to reverse string using pointers

C program to reverse string using pointers

C program to reverse string using pointers

#include<string.h>
void main()
{
char str[50];
char ch;
printf(“enter the string:\n”);
gets(str);
printf(“The reverse of a given string using pointers is %s\n”)
int length = strlen(str),
int t,i = length;
*t = ( str + i – 1 );
while(i<length/2)
{
ch = *str;
*str = *t;
*t = ch;
str++;
t–;
i++;
}
printf(“%c”, str);
}

C program to reverse string without strRev function using pointers and functions

C program to reverse string without strRev function

#include<stdio.h>
#include<string.h>
void main()
{
char a[50];
printf(“C program to find reverse of a string using pointers and functions \n”);
printf(“enter the string:\n”);
gets(a);
printf(“The reverse of a given string using pointers is %s\n”, reverse_str(a););
getch();
}
//reverse string function
char[] reverse_str(char *str)
{
int length = strlen(str),
int t,i = length;
char ch;
*t = ( str + i – 1 );
while(i<length/2)
{
ch = *str;
*str = *t;
*t = ch;
str++;
t–;
i++;
}
printf(“%c”, str);
}

c program to reverse string using recursion and pointers

c program to reverse string using recursion

#include<stdio.h>
void main()
{
char a[50];……
printf(“C program to find reverse of a string using recursion \n”);
printf(“enter the string:\n”);
gets(a);
printf(“The reverse a string using recursion is %s\n”, reverse_str(a););
getch();
}
void reverse_str(char *str)
{
if(*str!=’\0′)
{
reverse(str+1);// moves
printf(“%c”,*str);
}
}

 

c program to reverse string using arrays
write a c program to reverse string using arrays / WITHOUT STRREV

c program to reverse string using arrays

c program to find reverse string using arrays

#include<stdio.h>
#include<string.h>
void main()
{
char a[20] ;
printf(“C program to find reverse of a string using arrays  \n\n”);
printf(“enter a string to reverse\n”);
gets(a);
int len=strLen(a)
char temp;
for( i=0; i<len; i++)
{
temp=a[i];
a[i]=a[len];
a[len]=temp;
len–;
}
printf(“\t “, a);
}

c program to reverse string without strrev function using arrays and functions

c program to find reverse string without strrev function

#include<stdio.h>
#include<string.h>
void main()
{
char str[40] ;
printf(“C program to find reverse of a string using arrays and functions \n”);
printf(“enter a string to reverse\n”);
gets(str);
Reverse_string(str);
getch();
}

void Reverse_string(char a[40])
{
int len=strLen(a)
char temp;
for( i=0; i<len; i++)
{
temp=a[i];
a[i]=a[len];
a[len]=temp;
len–;
}
printf(“\t “, a);
}

c program to reverse string using strrev
c program to find reverse string using strrev

strRev function:
strrev function is used to find reverse of string is defined in string.h file. strrev function returns reverse of string defined in parameter

write a C program to find reverse of a string using strrev function

write a C program to find reverse of a string using strrev function

#include<stdio.h>
#include<conio.h>
// string.h has strrev function
#include<string.h>
void main()
{
char str[30],str1[30];
printf(“Enter string
gets(str);
str1=strrev(arr);
printf(“Reverse of a string using strrev is %s\n”,str1);
getch();
}

OUTPUT:

enter a string to reverse
programmingsimplysolved
reverse of a string using strRev is devlosylpmisgnimmargorp

write a c program to reverse N strings using strrev function

write a c program to reverse N strings using strrev function

#include<stdio.h>
#include<conio.h>
// string.h has strrev function
#include<string.h>
void main()
{
string str[30],str1[30];
int i=0,n;
printf(“Reversing N strings using strrev \n”);
printf(“Enter Number of string to be reversed \n”);
scanf(“%d”,&n);
while (i<n)
{
printf(“Enter the string\n “);
gets(str[i]);
i++;
}
for(i=0;i<n;i++)
{
str1[i]=strrev(str[i]);
printf(“Reverse of string %s using strrev is:  \n%s\n” str[i] , str1[i]);
getch();
}

write a c program to reverse string using stacks

write a c program to reverse string using stacks

#include<stdio.h>
#include<string.h>
int top=-1;
char stack[2O];
void main()
{
char str[20];
int len,i;
printf(“Enter string\n”);
scanf(“%s”,str);
len=strlen(str);
for(i=0;i<len;i++)
{
push(str[i],len);
}
printf(“The reverse of string %s using stacks is \t”, str);
for(i=0;i<len;i++)
{
pop();
}
getch();
}

void push(char c)
{
stack[top]=c;
top=top+1;
}

void pop()
{
printf(“%c”, stack[top]);
top–;
}

Other programs:

Static variable scope
Register variable scope
External variable scope
Automatic variable scope
amicable number
Prime number
Perfect number
Palindrome number
Strong number
Find Factorial 
Biggest Number
Average of n numbers
convert decimal number to octal
decimal number to hexadecimal
decimal number to binary
simple interest
compound interest
Add sparce matrices
Add matrices
 file copying
Palindrome string
Reverse string
String length
Replace characters in string
substring or not using arrays
First occurrence of character in string
Last occurrence of character in string
Convert to uppercase
Convert to lowercase
Concatenate strings 
Compare strings
Generate Employee payslips
Count students scoring marks>50%
convert weight into grams

 

Leave a Reply

Your email address will not be published. Required fields are marked *