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>
using namespace std;
int main(){
int value;
int range;
cout<<"Enter value: ";
cin>>value;
cout<<"Enter range: ";
cin>>range;
cout<<"\n Multiplication table up to "<<range<<" using for loop"<<endl;
//using for loop
for(int i=1;i<=range;i++){
cout<<value<<" * "<<i<<" = "<<value*i<<endl;
}
cout<<"\n Multiplication table up to "<<range<<" using while loop"<<endl;
//using while loop
int i=1;
while(i<=range){
cout<<value<<" * "<<i<<" = "<<value*i<<endl;
i++;
}
cout<<"\n Multiplication table up to "<<range<<" using do while loop"<<endl;
//using do while loop
int j=1;
do{
cout<<value<<" * "<<i<<" = "<<value*j<<endl;
j++;
}
while(j<=range);
return 0;
}
Comments
Leave a comment