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.
#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;
}
Comments
Leave a comment