Создайте функцию для отображения массива.

-5
A.nonymous 1 Апр 2017 в 07:24

2 ответа

Лучший ответ
#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-файла, которым вы поделились.

0
Ashish K 3 Апр 2017 в 14:24
#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;
}

Я запустил его в своей системе. Работает нормально!

0
Ashish K 1 Апр 2017 в 07:02