//code for reverse string
class ReverseString
{
public static void main(String arg[])
{
StringBuffer s=new StringBuffer("abcdef");
System.out.println("Before reversing :"+s);
s.reverse();
System.out.println("after reversing.."+s);
}
}
#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();
}
google_protectAndRun("ads_core.google_render_ad", google_handleError, google_render_ad);
Responses
No responses found. Be the first to respond and make money from revenue sharing program.
Feedbacks Popular Tags What are tags ? Search Tags Sign In to add tags. (No tags found.)
google_protectAndRun("ads_core.google_render_ad", google_handleError, google_render_ad);
Advertise Here
Watch TV Channels
/* using ellipses (...) to indicate tabs for clarity */
reverse (char *str) { /* print a string backwards */
... char *revstr = str; /* set to beginning of string */
... while (*revstr++ != '\0'); /* find end of string */
... revstr--; /* back up to the null */
... while (str <= revstr) printf ("%c", *--revstr); /* print each character - note pre decrement */
... printf ("\n"); /* print new-line */
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main(){
int i,j,k;
char str[20];
char temp[20];
printf("enter the string");
scanf("%d",&str);
char start=0;
for(i=0;i<strlen(str);i++)
{
if(str[i]==" " str[i]=='\0')
{
k=0;
for(j=0;j<i;j++)
{
temp[k]=str[i];
k++;
}
temp='\0';
strrev(temp);
printf("reverse the string %s",temp);
start=i+1;
}
}
return(0);
}
REM ***************************************
REM By Leo French
REM ***************************************
WORD$ = "Candy Apple Red"
L = LEN(WORD$): DIM N$(L)
FOR Y = 1 TO L: N$(Y) = MID$(WORD$, Y, 1): NEXT Y
TB = 50: PP = 0
CLS
FOR D = L TO 1 STEP -1
LOCATE 8, TB - PP: PRINT N$(D); : PP = PP + 1
SLEEP 1
NEXT D
Write your program and if you are having a problem post it here with a description of the problem you are having.
What you are asking is for someone to do your homework for you.
To reverse a number, first convert the number to a string, then reverse the string. Given your number consists of alphanumeric characters, the number must already be a string so simply reverse the string: #include<string> using std::string; string reverse (const string& s) { string str {}; for (auto c : s) str.insert (str.begin(), c); return str; } int main () { std::cout << "Enter a number: "; string s {}; std::cin >> s; std::cout << "The number in reverse is: " << reverse (s); }
Assume C#, not C: Traditional way: public string Reverse(string s) { if (string.IsNullOrEmpty(s)) return s; // "" or null char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } or as an extension method: public static string Reverse(this string s) { if (s == "") return ""; char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } The differences of the 2 methods above is on the caller (how to use Reverse()), and they may co-exist: For example: string test = "abc"; string result1 = Reverse(test); // traditional way string result2 = test.Reverse(); // call the extension
The following program prints every second character of the input in reverse order. #include<iostream> #include<sstream> int main() { std::cout << "Input:\t"; std::string input = ""; std::getline (std::cin, input); if (input.size()) { std::cout << "Output:\t"; unsigned index = input.size() / 2 * 2; do { index -= 2; std::cout << input[index]; } while (index); std::cout << std::endl; } }
void main() {char a[30] = "India"; //Let the string be stored in a[30]; char b[30]; //declaring another string for(i=0;i<strlen(a);i++) {b[strlen(a)-1 - i]=a[i];} //Now reverse string is stored in b; //to print it cout<<b; getch(); }
In order to program a reverse auto loan calculator in JAVA, you are going to need a lot of experience with JAVA. There are online tutorials that can help you set up with fundamentals of JAVA so that you will be able to create almost any basic program you want.
To reverse a number, first convert the number to a string, then reverse the string. Given your number consists of alphanumeric characters, the number must already be a string so simply reverse the string: #include<string> using std::string; string reverse (const string& s) { string str {}; for (auto c : s) str.insert (str.begin(), c); return str; } int main () { std::cout << "Enter a number: "; string s {}; std::cin >> s; std::cout << "The number in reverse is: " << reverse (s); }
Assume C#, not C: Traditional way: public string Reverse(string s) { if (string.IsNullOrEmpty(s)) return s; // "" or null char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } or as an extension method: public static string Reverse(this string s) { if (s == "") return ""; char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } The differences of the 2 methods above is on the caller (how to use Reverse()), and they may co-exist: For example: string test = "abc"; string result1 = Reverse(test); // traditional way string result2 = test.Reverse(); // call the extension
The following program prints every second character of the input in reverse order. #include<iostream> #include<sstream> int main() { std::cout << "Input:\t"; std::string input = ""; std::getline (std::cin, input); if (input.size()) { std::cout << "Output:\t"; unsigned index = input.size() / 2 * 2; do { index -= 2; std::cout << input[index]; } while (index); std::cout << std::endl; } }
You write the number and then follow it with the digits in reverse order.
void main() {char a[30] = "India"; //Let the string be stored in a[30]; char b[30]; //declaring another string for(i=0;i<strlen(a);i++) {b[strlen(a)-1 - i]=a[i];} //Now reverse string is stored in b; //to print it cout<<b; getch(); }
" A guitar string needs to be quite taut in order for it to produce an even tone."
In order to program a reverse auto loan calculator in JAVA, you are going to need a lot of experience with JAVA. There are online tutorials that can help you set up with fundamentals of JAVA so that you will be able to create almost any basic program you want.
I have no clue what you're asking, could you dumb it down for me.
import java.util.Arrays; public class arraysort { public static void main(String[] a) { int array[] = { 2, 5, -2, 6, -3 }; Arrays.sort(array); for (int i : array) { System.out.println(i); } } }
int n; // the number you want to reverse int rev_n = 0; while (n > 0) { // shift rev_n digits left rev_n *= 10; // put rightmost digit of n onto right of rev_n rev_n += n % 10; // remove rightmost digit of n n /= 10; }
Write the names in order on a piece of paper, then turn it upside down and you can read the names in reverse order.
foreach char in string push on to stack create new string foreach char in string pop off and add to end of new string if new string equals old string palindrome else not palindrome //when you pop off the stack, the characters come off in reverse order, thus you have reversed the original string