gpt4 book ai didi

c - 函数内的数组

转载 作者:行者123 更新时间:2023-11-30 21:39:00 25 4
gpt4 key购买 nike

创建一个显示数组的函数。

最佳答案

#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;
}

我认为您最好看一下代码。我已经在代码中使用 ///* */ 提到了注释。正确阅读评论。我已经检查了我的系统上适用于 10 个问题的代码,因此如果您按照我编写的模式完成操作,就不会出现错误。并且不要忘记查看公式。数组索引需要根据您共享的原始pdf中的公式。

关于c - 函数内的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43152811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com