Tuesday, December 19, 2017

C++ Code Review: Reverse strings stored at array

Description: This program reverse strings stored at array.

Code:

//Compiling Tool: Code::Block IDE with MinGW

//Program reverse strings stored at array.

 

#include<iostream>

#include<stdio.h> //used for gets()

#include<string.h>

 

using namespace std;

 

int main()

{

    char a[3][50];

    int i,j,k,len;

 

    cout<<"Enter 3 strings:\n";

 

    for(i=0;i<3;i++)

    {

        gets(a[i]);

    }

 

    cout<<"\nThe list of original strings:\n" ;

 

    for(i=0;i<3;i++)

    {

        cout<<a[i]<<"\n";

    }

 

    cout<<"\nThe list of changed strings:\n";

 

    for(i=0;i<3;i++)

    {

        len=strlen(a[i]);

        for(j=0,k=len-1;k>=0;j++,k--)

        {

            cout<<a[i][k];

        }

 

        cout<<"\n";

    }

 

    return 0;

}            

 Output:

clip_image002

If you want to write or construct or program C++ mini-project and do not know how or from where to start buy this simple e-book: Code Review of 26 C++ mini-projects. For book sample click this link.

Add your comments in below available comment box.

Note: Click these label/tags to view all related posts. Tags: C++Code

 

…till next post, bye-bye & take care.

No comments:

Post a Comment