/* Program to print reverse string by using stack */
#include
#include
typedef struct stack
{
char b[100];
int top;
}stack;
void push(stack *s,char k)
{
if(s->top==99)
printf("\n Stack is full ");
else
s->b[++s->top]=k;
}
char pop(stack *s)
{
char c;
if(s->top==(-1))
printf("\n Stack is empty");
else
else
c=s->b[s->top--];
return c;
}
void main()
{
char name[100];
stack s;
clrscr();
s.top=-1;
printf("\nEnter name :");
gets(name);
int i=0;
while(name[i]!='\0')
{
push(&s,name[i]);
i++;
}
printf("\n Reverse string is :");
while(s.top!=-1)
{
printf("%c",pop(&s));
}
getch(); }
/* Program of reversing a string using stack */
#include
#define MAX 20
#include
int top = -1;
char stack[MAX];
char pop();
push(char);
main()
{
char str[20];
int i;
printf("Enter the string : " );
gets(str);
/*Push characters of the string str on the stack */
for(i=0;i
push(str[i]);
/*Pop characters from the stack and store in string str */
for(i=0;i
str[i]=pop();
printf("Reversed string is : ");
puts(str);
}/*End of main()*/
push(char item)
{
if(top == (MAX-1))
printf("Stack Overflow\n");
else
stack[++top] =item;
}/*End of push()*/
char pop()
{
if(top == -1)
printf("Stack Underflow\n");
else
return stack[top--];
}/*End of pop()*/
#include
#include
typedef struct stack
{
char b[100];
int top;
}stack;
void push(stack *s,char k)
{
if(s->top==99)
printf("\n Stack is full ");
else
s->b[++s->top]=k;
}
char pop(stack *s)
{
char c;
if(s->top==(-1))
printf("\n Stack is empty");
else
else
c=s->b[s->top--];
return c;
}
void main()
{
char name[100];
stack s;
clrscr();
s.top=-1;
printf("\nEnter name :");
gets(name);
int i=0;
while(name[i]!='\0')
{
push(&s,name[i]);
i++;
}
printf("\n Reverse string is :");
while(s.top!=-1)
{
printf("%c",pop(&s));
}
getch();
}
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char str[10],temp;
int i,len;
printf("Enter String : ");
scanf("%s",str);
len=strlen(str)-1;
for(i=0;i<strlen(str)/2;i++)
{
temp=str[i];
str[i]=str[len];
str[len--]=temp;
}
printf("%s",str);
getch();
#include<conio.h>
#include<string.h>
void main()
char name[25] rev[25];
int i l;
printf( enter the name );
gets(name);
l strlen(name);
for(i 0;i<l;i++)
name[i] rev[l-1-i];
i++;
}
getch();
/*without using standard functions*/
#include<stdio.h>
#include<string.h>
#include <conio.h>
main()
char s[40] c r[40];
int i j p;
clrscr();
printf( Enter the string: );
gets(s);
for(i 0;s[i]! ' ';i++);
j i;
printf( The original string is: s s);
printf( nThe reverse string is: );
for(p j-1 i 0;p> 0;p-- i++)
r[i] s[p];
r[i] ' ';
printf( The reverse string is: s r);
getch();
}
#include <stdio.h>
#define REVERSE_STRING(X) Rstring(X, *(X), strlen(X)-1)
void Rstring( char *str, char c, int index )
{
if( index != 0 )
Rstring( str, *(str+(strlen(str))-index),
index-1);
*(str+index) = c;
}
int main( void )
{
char str[] = "Dharmendra Patel";
printf("Actual string is [%s]\n", str);
REVERSE_STRING(str);
printf("Reversed string is [%s]\n", str);
return 0;
}
1. #include<stdio.h>
2. #include<conio.h>
3. void main()
4. {
5. char name[10]={0,0,0,0,0,0,0,0,0,0};
6. char namre[10]={0,0,0,0,0,0,0,0,0,0};
7. int i=0,a=0,j,q=0,num=0;
8. clrscr();
9. printf("Please Enter The Number Of Leters In Your Word");
10. scanf("%d",&num);
11. printf("enter\n");
12. for(i=0;i<num;i++)
13. {
14. name[i]=getche();
15. a++;
16. }
17. printf("\n");
18. q=a;
19. for(j=0;j<a;j++)
20. {
21. q--;
22. namre[q]=name[j];
23. if(namre[q]==name[j])
24. {
25. printf("the word is same");
26. break;
27. }
28. else
29. {
30. printf("the word is not same");
31. break;
32. }
33. }
34. getch();
35. }