0% found this document useful (0 votes)
32 views

#Include #Include Using Namespace Void

This C++ document contains 3 programs to reverse a string. The first program uses a for loop to iterate through the string from the last index to the first, outputting each character. The second program uses a function called strrev to reverse the string and output it. The third program uses pointers to iterate from the end of the string to the beginning, copying each character to the reverse string.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

#Include #Include Using Namespace Void

This C++ document contains 3 programs to reverse a string. The first program uses a for loop to iterate through the string from the last index to the first, outputting each character. The second program uses a function called strrev to reverse the string and output it. The third program uses pointers to iterate from the end of the string to the beginning, copying each character to the reverse string.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

// reverse a line .

#include<iostream> #include<cstring> using namespace std; void main() { char a[20];//a1[20]; int i,j; cout<<"Enter any String:"<<"\n"; cin.getline(a,20 ); cout<<"Reverse of the string is: "; for(i=0;a[i]!='\0';++i); for(j=i-1;j>=0;--j) cout<<a[j];

} char * rev rev= strrev(a); // working; cout<<rev; #include <iostream> using namespace std; int *pn; int a; void cube () { int l = *pn; l= l*l*l; cout<<l; cout<<'\n'; } void square () { int l = *pn; l= l*l; cout<<l; cout<<'\n'; }

void main() { pn= &a; cin>>a; cout<<'\n'; cout<<'\n'; cout<<'\n'; cube(); square(); }

#include<stdio.h> int main(){ char str[50]; char rev[50]; char *sptr = str; char *rptr = rev; int i=-1; printf("Enter any string : "); scanf("%s",str); while(*sptr){ sptr++; i++; } while(i>=0){ sptr--; *rptr = *sptr; rptr++; --i; } *rptr='\0'; printf("Reverse of string is : %s",rev); return 0; }

You might also like