Write a c++ program to display numbers which is divisible by 2 as well 3 from 6 to n by using For loop and if else statement .
/* Write a c++ program to display numbers which is
divisible by 2 as well 3 from 6 to n by using
a) For loop and if-else statement */
#include <iostream>
using namespace std ;
int main ()
{ int i ,n ;
cout<< "upto n"<<endl ;
cout<<"Enter the n( more than 6 ) ";
cin>>n;
for( i= 6; i <= n ; i++)
{ if ( i %2 ==0 )
{ if (i %3==0)
{ cout<< i <<" , "; }
}
}
return 0;
}
output :
upto n
Enter the n( more than 6 ) = 45
6 , 12 , 18 , 24 , 30 , 36 , 42 , more exercise
Comments
Post a Comment
If you have any doubt ,let me know