Experiment 7: Aim - Write A Program To Reverse A String. Source Code

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Experiment 7

Aim – Write a program to reverse a string.

Source Code –
#include <stdio.h>
#include <string.h>
void swap(char *,char *);
int main()
{
char str[20];
unsigned long p;
printf("Enter the sting\n");
gets(str);
p= strlen(str);
for (int i=0;i<=(p/2)-1;i++)
{
swap(&str[i],&str[p-i-1]);
}
puts(str);
return 0;
}
void swap (char*a, char*b)
{
*a=*a+*b;
*b=*a-*b;
*a=*a-*b;
}
Output –

You might also like