Computer Science, asked by Arsh9820, 1 year ago

Write a program to implement to reverse the following string : “ ABCDEFGH” and calculate (i) Total number of exchange operations (ii) Total number of comparison operations (iii) Total number of times the loop will execute

Answers

Answered by DeVasu
1
Program in C++

#include<iostream.h>
#include<string.h>

using namespace std;

int main()
{
    char a[9] = "ABCDEFGH";
    int ex=0,cmp=0,loop=0;
    for(int i=0;i<4;i++)
        {
                char temp = a[8-i];
                a[8-i] = a[i] ; ex++;
                a[i] = temp; loop++;
         }
cout<<"\n The string has been reversed";
cout<<"\n The loop was executed "<<loop<< " times and exchange took place "<<ex<<" times";

return 0;

}
               

Similar questions