Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 数组内部函数_C_Arrays_Function_For Loop_Codeblocks - Fatal编程技术网

C 数组内部函数

C 数组内部函数,c,arrays,function,for-loop,codeblocks,C,Arrays,Function,For Loop,Codeblocks,创建一个函数来显示数组 #包括 #include<stdio.h> #define SIZE 5 int scoreList[SIZE]; int i; int findTotal(int scoreList[SIZE], int inSmall, int inLarge){ int total =0; int index; for (index = 0; index < SIZE; index++) {

创建一个函数来显示数组

#包括
#include<stdio.h>

#define SIZE 5

int scoreList[SIZE];
int i;

int findTotal(int scoreList[SIZE], int inSmall, int inLarge){
        int total =0;
        int index;
        for (index = 0; index < SIZE; index++)
        {
                if (scoreList[index]!= inSmall && scoreList[index]!= inLarge)
                total = total + scoreList[index];
        }
        return total;
}
int findLarge(int scoreList[SIZE]){
        int index;
        int largest = scoreList[0];
        for (index=1; index < SIZE; index++)
        {
                if (scoreList[index] > largest)
                largest = scoreList[index];
        }
        return largest;
}
int findSmall(int scoreList[SIZE]){
        int index;
        int smallest = scoreList[0];
        for (index=1; index < SIZE; index++)
        {
                if (scoreList[index] < smallest)
                smallest = scoreList[index];
        }
        return smallest;
}

int main(){

        const char* question[] = { "I don't talk a lot", "I have people around me", "I love nature", "I talk about science", "And bla bla bla" };

        // char question[SIZE][100] = {"I don't talk a lot","why this is good","one two","fourth","fifth"}; // If you don't wish to use pointer, You will have to use a 2D char array that will store the total number of element and second one will store length of each element (here 100)

        for(i=0; i<SIZE; i++){
                printf("%s :\nYour Score: ", question[i]);
                scanf("%d", &scoreList[i]);
        }

        int smallest = findSmall(scoreList);
        int largest = findLarge(scoreList);
        int total = findTotal(scoreList, smallest, largest);

        printf("smallest: %d, largest: %d, total: %d\n", smallest, largest, total);
return 0;
}
#定义尺寸5 整数计分表[大小]; int i; int findTotal(int计分表[大小]、int inSmall、int INSLARGE){ int-total=0; 整数指数; 对于(索引=0;索引最大值) 最大=得分列表[索引]; } 回报最大; } int findSmall(int scoreList[大小]){ 整数指数; int最小=得分列表[0]; 对于(索引=1;索引#包括 #定义分配给每个问题的最大尺寸100 #定义问题的数量10 int scoreList[NUMBER_OF_QUESTIONS];//此数组将包含各个问题的每个答案的单独分数 int i; 虚无外向型(整数分数表[]){ //设其公式为E=20+(1)-(3)-(2)-(4)___ INTE=20+(分数表[1]+分数表[2])-(分数表[3]+分数表[4]); printf(“\nExtroversion是一种从自我或社区之外的资源中寻求满足感的人格特征。得分高的人往往非常善于社交,而得分低的人更喜欢独自完成他们的项目。\n你对这一特征的得分是:%d\n\n”,E); } 无效宜人性(int计分表[]){ //设其公式为A=14-(2)u_+(5)__-(3)_+(6)___ INTA=20+(分数表[5]+分数表[6])-(分数表[2]+分数表[3]); printf(“\nAgreeability反映了许多人调整自己的行为以适应他人。得分高的人通常是有礼貌的,喜欢别人。得分低的人倾向于“如实地说”。\n你对这一特征的得分是:%d\n\n”,A); } /* *同样地,对于责任心、神经质和对经验的开放性 */ int main(){ const char question[问题数量][每个问题分配的最大尺寸]={“1.我是党的生命”,“2.不关心他人”,“3.我总是有准备”,“4.容易感到压力”,“5.有丰富的词汇”,“6.不要说太多”,“7.我对人感兴趣”,“8.把我的东西放在身边”,“9.我大部分时间都很放松。”,“10.难以理解抽象概念。”};
对于(i=0;i
const char*questions[]={“Question1”、“Question2”、…}
@A.nonymous如果您对
char*
char
不清楚,您必须开始学习Cbasic@A.nonymous,使用上面的你可以得到包含个人分数的数组列表。现在你可以相应地使用数组来取消你的其他必备条件。如果你想问什么,请告诉我!如果你想问,请不要担心尚未了解
char*
。它被称为指针(pointer),一个存储实际数据位置地址的值,如果你要学习C编程,这是最有用的东西之一。如果你经常练习,这并不难学。你可以学习关于指针的教程和课程在互联网上。对于你的下一个查询:
const char*question[]={“在双引号内写任何东西”,“你想要的任何东西”,“每个元素都将被视为一个元素”,“对于给定的数组问题”,“Q5”};
我正在正确地为你写代码。给我一点时间,这不是我要问的,但没关系。
scanf(“%d”&scoreList[I]);//这里每个元素都存储了对应问题的0-5之间的值
我不理解这一部分。0-5还没有定义或声明。非常感谢。我会一遍又一遍地阅读您的代码和注释。我非常感谢您。如果您不介意,请删除前面的答案,然后再来nts?再次感谢。或者将scanf修改为
scanf(“%[1-5]d,scoreList[i]”)
只取1-5之间的整数,或print告诉用户只输入1-5之间的整数。这两种方法都对您有好处。哦,我明白了。我会使用print,因为我已经学会了。谢谢。我现在明白我的错误所在。我太关注char了,而不是使用int表示E,等等。我使用char。我们需要函数定义吗?
#include<stdio.h>

#define MAX_SIZE_ALLOTED_TO_EACH_QUESTION 100
#define NUMBER_OF_QUESTIONS 10

int scoreList[NUMBER_OF_QUESTIONS]; // This array will contain the individual score for each answers to respective questions
int i;

void Extroversion(int scoreList[]){

        // Let formula for this be E = 20 +(1)___-(3)___+(2)___-(4)___
        int E = 20 + (scoreList[1] + scoreList[2]) - (scoreList[3] + scoreList[4]);
        printf("\nExtroversion is the personality trait of seeking fulfillment from sources outside the self or in community. High scorers tend to be very social while low scorers prefer to work on their projects alone.\nYour score for this trait is: %d\n\n", E);
}

void Agreeableness(int scoreList[]){

        // Let formula for this be A = 14 -(2)___+(5)___-(3)___+(6)___
        int A = 20 + (scoreList[5] + scoreList[6]) - (scoreList[2] + scoreList[3]);
        printf("\nAgreeableness reflects much individuals adjust their behavior to suit others. High scorers are typically polite and like people. Low scorers tend to 'tell it like it is'.\nYour score for this trait is: %d\n\n", A);
}

/*

* Similarily for Conscientiousness, Neuroticism and Openness_to_Experience

*/


int main(){

        const char question[NUMBER_OF_QUESTIONS][MAX_SIZE_ALLOTED_TO_EACH_QUESTION] = { "1. Am the life of the party.", "2. Feel little concern for others.", "3. Am always prepared.", "4. Get stressed out easily.", "5. Have a rich vocabulary.", "6. Don't talk a lot.", "7. Am interested in people.", "8. Leave my belongings around.", "9. Am relaxed most of the time.", "10. Have difficulty understanding abstract ideas." };

        for(i=0; i<NUMBER_OF_QUESTIONS; i++){
                printf("%s :\nYour Score: ", question[i]);
                scanf("%d", &scoreList[i]); // Here each element is storing the value between 0-5 for their corresponsding question
 }

        Extroversion(scoreList);
        Agreeableness(scoreList);
//      Conscientiousness(scoreList);
//      Neuroticism(scoreList);
//      Openness_to_Experience(scoreList);

return 0;
}