Answer to Question #190725 in C++ for Salwa Ikram

Question #190725

Differentiate between different loops in form of table and write a same logic programe by using all loops, programe mentioned below:

Programe: Write a programe that input value and range from user,

Display multiplication table up to a given range by using For ,while and do-while loops.


1
Expert's answer
2021-05-08T07:26:00-0400
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
    cout<<"Input value: ";
    int value; cin>>value;
    cout<<"Input range: ";
    int range; cin>>range;
    cout<<"\nFor Loop\n";
    int i = 0, w = 2;
    for(i = 0; i <= range; i++){
        cout<<setw(w)<<value<<" x "<<setw(w)<<i<<" = "<<setw(w)<<value * i<<endl;
    }
    cout<<"\nWhile loop\n";
    i = 0;
    while(i <= range){
        cout<<setw(w)<<value<<" x "<<setw(w)<<i<<" = "<<setw(w)<<value * i<<endl;
        i++;
    }
    cout<<"\nDo While loop\n";
    i = 0;
    do{
        cout<<setw(w)<<value<<" x "<<setw(w)<<i<<" = "<<setw(w)<<value * i<<endl;
        i++;
    }while(i <= range);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment