Given n numbers , count all
the multiples of 3 from the n numbers.
Implementation:
INPUT
First line - integer n.
N lines follow, each containing a positive integer a[i], 1<=i<=n.
OUTPUT
The required "count"
Sample Input
2
3
4
5
6
7
8
9
10
Method 1: (Brute Force)
1. Read an integer
2. Check if 3 divides the number, increment count if YES
3. Finally, Print the count
Implementation:
#include <stdio.h>
int main()
{
long int N,i,c=0;
scanf("%ld",&N);
while(N--)
{
scanf("%ld",&i);
if(i%3==0)
c++;
}
printf("%ld",c);
return 0;
}
First line - integer n.
N lines follow, each containing a positive integer a[i], 1<=i<=n.
OUTPUT
The required "count"
Sample Input
10
1 2
3
4
5
6
7
8
9
10
Sample Output
3