C 如何计算输入文件中数字的倍数?

C 如何计算输入文件中数字的倍数?,c,C,我试图从用户输入文件中分别计算2、3和6的倍数。但由于某种原因,我的计数器不工作。有人能帮我吗。 我的代码: #包括 内部主(空) { int num[12]; int i; int count2; int count3; int count6; int-total=0; printf(“输入12个整数:\n”); 对于(i=0;i,在每个迭代步骤中重置计数器变量 counttwo=0; countthree=0; countsix=0; 在第二个循环中的counttwo,countthree

我试图从用户输入文件中分别计算2、3和6的倍数。但由于某种原因,我的计数器不工作。有人能帮我吗。 我的代码:

#包括
内部主(空)
{
int num[12];
int i;
int count2;
int count3;
int count6;
int-total=0;
printf(“输入12个整数:\n”);

对于(i=0;i,在每个迭代步骤中重置计数器变量

counttwo=0;
countthree=0;
countsix=0;

在第二个循环中的
counttwo
countthree
countsix
的值发生了什么变化。请特别注意行
counttwo=0
countthree=0
,以及
countsix=0
  • 在循环的
    之前,将
    counttwo
    countthree
    countsix
    重置为0
  • 为循环删除冗余的
    scanf
  • 将3
    printf
    移出循环的
    for
  • 这是固定代码

    #include <stdio.h>
    int main (void)
    {
      int num[12];
      int i;
      int counttwo = 0; //Reset counttwo, countthree, and countsix to 0
      int countthree = 0;
      int countsix = 0;
      int total=0;
      printf("enter 12 integer numbers:\n");
    
      for(i=0;i<12;i++){
    
          scanf("%d", &num[i]);
    
          if(num[i]%2==0){
           counttwo++;
          }
    
          if(num[i]%3==0){
           countthree++;
          }
    
          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;
    
    }
    
    #包括
    内部主(空)
    {
    int num[12];
    int i;
    int counttwo=0;//将counttwo、countthree和countsix重置为0
    int countthree=0;
    int countsix=0;
    int-total=0;
    printf(“输入12个整数:\n”);
    
    对于(i=0;i8个问题但没有被接受的答案?将其传递。我认为这需要一个
    家庭作业
    标记。你需要学习适当缩进的价值。你能转到你以前的问题并接受回答你提出的问题的答案吗?我们在这里工作是为了得分!!!太好了!谢谢你让我犯了这么多小的错误一周一次。再次感谢!我能够得到倍数,但我也试图通过在末尾添加一个代码来打印出2的倍数:for(j=0;j)
    
    #include <stdio.h>
    int main (void)
    {
      int num[12];
      int i;
      int counttwo = 0; //Reset counttwo, countthree, and countsix to 0
      int countthree = 0;
      int countsix = 0;
      int total=0;
      printf("enter 12 integer numbers:\n");
    
      for(i=0;i<12;i++){
    
          scanf("%d", &num[i]);
    
          if(num[i]%2==0){
           counttwo++;
          }
    
          if(num[i]%3==0){
           countthree++;
          }
    
          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;
    
    }