Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        2年前关闭。
                                                                                            
                
        
我必须输出每个测试分数,每行5分,最后是三分。有没有办法使代码更短,如更少的代码?

int arrayDisplay(int testScore[], int size){

    printf("%d %d %d %d %d", testScore[0], testScore[1], testScore[2], testScore[3], testScore[4]);
    printf("\n");
    printf("%d %d %d %d %d", testScore[5], testScore[6], testScore[7], testScore[8], testScore[9]);
    printf("\n");
    printf("%d %d %d %d %d", testScore[10], testScore[11], testScore[12], testScore[13], testScore[14]);
    printf("\n");
    printf("%d %d %d %d %d", testScore[15], testScore[16], testScore[17], testScore[18], testScore[19]);
    printf("\n");
    printf("%d %d %d %d %d", testScore[20], testScore[21], testScore[22], testScore[23], testScore[23]);
    printf("\n");
    printf("%d %d %d %d %d", testScore[24], testScore[25], testScore[26], testScore[27], testScore[28]);
    printf("\n");
    printf("%d %d %d", testScore[29], testScore[30], testScore[31]);
    printf("\n");

    return 0;
}

最佳答案

我觉得这样做有点脏,但是:

    int arrayDisplay(int *testScore, int size)
    {
        for (int i = 0 ; i < size; i++)
        {
          printf("%d ", testScore[i]);
          if (i%5==0)
          {
            printf("\n");
          }

        }

    return 0;

    }


需要明确的是:SO通常不会善待这些类型的问题。认为这是您的一个免费;

关于c - 如何缩短?有办法吗? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47321761/

10-08 23:07