Tuesday, February 28, 2017

(12) Write a Program to enter any number and check (i)it is divisible by 3 only (ii) it is divisible by 5 only (iii) it is divisible by 3 & 5 both in Cpp

vProgram
/*WAP divisible by 3 and 5 or both */
#include<iostream.h>
#include<conio.h>
void main()
{
 int no;
 clrscr();
 cout<<"\n\t\t Enter Number :";
 cin>>no;
 if(no%3==0)
 {
  if(no%5==0)
  {
    cout<<"divisible by 3 & 5";
    }
    else
    {
    cout<<"divisible by 3 Only";

    }
   }
   else
   {
      if(no%5==0)
      {
       cout<<"\n\t\t Divisible By 5 Only";
      }
      else
      {
       cout<<"\n \t\tnot Divisible 5 & 3";
       }
    }
    getch();
  }
vOutput

Enter number:30
Divisible by 3 & 5

No comments:

Post a Comment