how to count multiples of numbers in an input file?

Posted by user292489 on Stack Overflow See other posts from Stack Overflow or by user292489
Published on 2010-05-02T18:49:36Z Indexed on 2010/05/02 18:57 UTC
Read the original article Hit count: 128

Filed under:
|

i was trying to count the number of multiples of 2, 3, and 6 respectielly from the users input file. but for some reason, my counter is not working. can any bosy hep me please. my code:

#include <stdio.h>
int main (void)
{
  int num[12];
  int i;
  int counttwo;
  int countthree;
  int countsix;
  int total=0;
  printf("enter 12 integer numbers:\n");
  for(i=0;i<12;i++){

 scanf("%d", &num[i]);
  }
  for(i=0;i<12;i++){
    counttwo=0;
      if(num[i]%2==0){
       counttwo++;
      }
      countthree=0;
       if(num[i]%3==0)
  {
      countthree++;
   }
       countsix=0;
      if(num[i]%6==0)
        {
          countsix++;
}
      printf("There are %d multiples of 2:\n", counttwo);
      printf("There are %d multiples of 3:\n", countthree);
      printf("There are %d multiples of 6:\n", countsix);
}
  return 0;

}

© Stack Overflow or respective owner

Related posts about c

    Related posts about homework