Q. 3 and 7
Problem link
Score: 1
CPU: 1s
Memory: 512MB
CPU: 1s
Memory: 512MB
Given
N you have to find out whether N is divisible by 3 and 7 or not.
Input
First you will be given an positive integer
Output
For each test case you have to print “
First you will be given an positive integer
T (1< T < 100), the number of test case. For each test case you will be given N( 1 < N < 1000) in different lines.Output
For each test case you have to print “
N is divisible by 3” if N is divisible by 3 and “N is not divisible by 3” if N is not divisible by 3. After that if N is divisible by 3 then if N is also divisible by 7 then you have to print one extra line “N is also divisible by 7”. See the sample i/o for better understandings.Sample
| Input | Output |
|---|---|
| 3 9 21 25 | 9 is divisible by 3 21 is divisible by 3 21 is also divisible by 7 25 is not divisible by 3 |
Solution
#include<stdio.h> int main() { int a,b,i; scanf("%d",&a); for(i=1;i<=a;i++){ scanf("%d",&b); if(b%3==0){ printf("%d is divisible by 3\n",b); if(b%7==0){ printf("%d is also divisible by 7\n",b); } } else{ printf("%d is not divisible by 3\n",b); } } return 0; }
No comments:
Post a Comment