P. Divisible by 3
Problem link
https://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/P
Score: 1
CPU: 1s
Memory: 512MB
CPU: 1s
Memory: 512MB
Given
Input
First you will be given an positive integer
Output
For each test case print “
N
you have to find out the total number of integer between 0
to N
is divisible by 3
.Input
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 print “
Case X: R
”. Where X
is the running test case number and R
is the total amount of integer divisible by 3
between 0
and N
.Sample
Input | Output |
---|---|
3 6 9 12 | Case 1: 3 Case 2: 4 Case 3: 5 |
Solution
#include<stdio.h>
int main()
{
int count,n,i,j,t;
scanf("%d",&t);
for(j=1;j<=t;j++){
count=0;
scanf("%d",&n);
for(i=0;i<=n;i++){
if(i%3==0){
count++;
}
}
printf("Case %d: %d\n",j,count);
}
return 0;
}
No comments:
Post a Comment