-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReverse_a_string_using_STACK.c
46 lines (37 loc) · 1016 Bytes
/
Reverse_a_string_using_STACK.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// ABC international is checking the company names of its client for palindrome. A string is said to be palindrome if both the input string and the reversed output string are one and the same. So ABC international needs to reverse the names of the companies they have. Write a program to reverse a string using stack implementation. Remember as stack uses LIFO concept the string pushed can be popped out in a reverse order.
// Constraint: String can be of size 10.
// Input: Input string S
// Output: Reverse of a string given as input or overflow if string is above size 10.
// Test Case 1:
// Input:
// madam
// Output
// madam
#include<stdio.h>
#include<string.h>
char s[100];
int top=-1;
void push(char e)
{
top++;
s[top]=e;
}
void display()
{
while(top>=0)
{
printf("%c",s[top]);
top--;
}
}
int main()
{
char ch[100];
scanf("%s",ch);
for(int i=0;i<strlen(ch);i++)
push(ch[i]);
if(strlen(ch)>10)
printf("Overflow");
else
display();
}