To print table of any number ; input of the number is taken by the user ; using for loop
#include<iostream>
using namespace std;
int main()
{
float i;
int x;
cout <<"table of any number" <<endl <<"enter the number whose table is to be write" <<endl ;
cin>> i;
for(x=1;x<11;x++)
{
cout <<x <<"x" <<i <<"=" <<x*i << endl ;
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
float i;
int x;
cout <<"table of any number" <<endl <<"enter the number whose table is to be write" <<endl ;
cin>> i;
for(x=1;x<11;x++)
{
cout <<x <<"x" <<i <<"=" <<x*i << endl ;
}
return 0;
}
while loop
#include<iostream>
using namespace std;
int main()
{
int i=1,j;
cout <<"enter the last number" <<endl ;
cin>>j;
cout <<"this is our counting from 1" << endl;
while(i<=j)
{
cout<<i <<endl;
i++;
}
}
do while loop
#include<iostream>
using namespace std;
int main()
{
int a,b;
cout << "enter the first and last number " <<endl;
cin>>a;
cin>>b;
int c =a;
cout<<"the series is " <<endl;
do
{
cout<< c <<endl;
c+=2;
}
while (c<=b);
}
#include<iostream>
using namespace std;
int main()
{
int a,b;
cout << "enter the first and last number " <<endl;
cin>>a;
cin>>b;
int c =a;
cout<<"the series is " <<endl;
do
{
cout<< c <<endl;
c+=2;
}
while (c<=b);
}
output
No comments:
Post a Comment