‘C’ program to check if number is divisible by 3 or 5.

C File =>


/* Write a ‘C’ program to accept an integer and check if it is divisible by 
3 and 5. */

#include<stdio.h>
int main() 
{
       int num;
 
       printf("\n Enter number : ");
       scanf("%d",&num);
 
       if(num%3==0 && num%5==0)
             printf("\n %d is divisible by both 3 and 5",num);
      else if(num%3==0)
             printf("\n %d is divisible by only 3",num);
      else if(num%5==0)
             printf("\n %d is divisible by only 5",num);
     else
             printf("\n %d is not divisible by 3 and 5",num);
  
     return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.