我怎样才能重写这个程序,以便它以相反的顺序打印文本的值


#include<iostream.h>
#include<conio.h>
#include<string.h>
char text[]="A nut for a jar of tuna";
int txtposition,txtlength;
void main()
{
    clrscr();
    txtlength=Strlen(text);
    for(txtposition=0; txtposition<=txtlength;txtposition++)
     { 
         cout<<text[txtposition]; 
     }
getch();
}

如何重写此程序,使其以相反的顺序打印文本的值?

#include<iostream.h>
#include<conio.h>
#include<string.h>
char text[]="A nut for a jar of tuna";
int txtposition,txtlength;
void main()
{
    clrscr();
    txtlength=Strlen(text);
    for(txtposition= txtlength-1 ; txtposition>=0;txtposition--)
     { 
         cout<<text[txtposition]; 
     }
    getch();
}

您可以使用@Prashant建议的答案,也可以创建另一个char reversetext[],您可以在其中保存反向文本。这样,您可以根据需要使用它。

此外,如果您尝试反转每个单词,则需要不同的更长算法。如果您正在寻找,请告诉我。

最新更新