"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Tuesday, March 2, 2010

Write a C++ program to print every integer between 1 and n divisible by m. Also report whether the number that is divisible by m is even or odd.


#include<iostream.h>
#include<conio.h>
#include<process.h>

void main()
{
int n, m;

cout<< "\n Enter the value of n :";
cin >> n;

cout<< "\n Enter the value of m :";
cin >> m;

if(m>n)
{cout<< "\n The number " << n << "  is not divisible by "  << m;
getch();
exit(1);
}

for( int  i = n ; i > = m ; i-- )
{
if(i % m == 0)
{
   cout << "\n " << i << "  is divisible by " << m;
   if(i%2 == 0)
        cout<< "\n The number " << i << "Even";
   else
        cout<< "\n The number " << i << "Odd";
}
}

getch();
}










1 comment:

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.