Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am writing a program that reads ten integers from standard input, and determin

ID: 3800412 • Letter: I

Question

I am writing a program that reads ten integers from standard input, and determines if they are going up or down or neither. Can I get some help? I have supplied what I have already.

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

int isGoingUp(int [a]);

int isGoingDown(int [b]);

int main(void) {

int array[10];

printf("Enter ten integers : ");

for (int a = 0; a < 10; a++) scanf("%d", &array[a]);

if (isGoingUp(array) == 1)

printf("The values are going up ");

else if (isGoingDown(array) == 1)

printf("The values are going down ");

else

printf("The values are neither going up or going down ");

return 0;

}

Explanation / Answer

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

int isGoingUp(int a[10])
{
    int i,flag = 1;    //array is going up or in ascending order
    for(i=0;i<10;i++)
    {
        if(a[i] > a[i+1]) // if descending order set flag = 0
        {
            flag = 0;
        }
    }
  
    return flag;
}

int isGoingDown(int b[10])
{
    int i,flag = 1;    //array is going up or in descending order
    for(i=0;i<10;i++)
    {
        if(b[i] < b[i+1]) // if ascending order set flag = 0
        {
            flag = 0;
        }
    }
  
    return flag;
}

int main(void)
{

int a,array[10];

printf("Enter ten integers : ");

for (a = 0; a < 10; a++)
scanf("%d", &array[a]);

if (isGoingUp(array) == 1)

printf("The values are going up ");

else if (isGoingDown(array) == 1)

printf("The values are going down ");

else

printf("The values are neither going up or going down ");

return 0;

}

Output:

Enter ten integers :23 20 16 15 10 8 6 3 2 1

The values are going down

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote