Question

Write a C program that reads a sequence of numbers and display a message 1. The numbers a re red from the standard input. 2. The first number is the length of the sequence (n) followed by n numbers. 3. If n is 0 or negative, the program displays the message Error_1 followed 4. If the length is shorter than n, it displays Error_2 followed by a new line 5. The program inspects the list and display one of the following messages by a new line on the standard input. and quits. (every one oi the is followed by a newline) Ascending if the list is strictly ascending. That is every number is .Descending if the list is strictly descending. That is every number is .Not Descending if the list is ascending. That is every number is .Not Ascending if the list is ascending. That is every number is less greater than the previous one for example 1 4 6 8 12 34 less than the previous one for example 78 34 29 15 8 greater than or equal the previous one 1 3 59 9 12 17 than or equal the previous one. For example 100 89 89 73 45 3 example 55555555 .EQUAL this is the case when all the numbers are the same for

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/******************************************************************************

Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>
#include <stdbool.h>

int main()
{
int n;
bool equal=false;
printf("Enter array length followed by array inputs\n");
scanf("%d",&n);

if(n<=0) {printf("Erro1"); exit(0);}
int a[n];
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
///////////////////////////////////////////////
//first im checking for Ascending or Not (greater than condition)
//after that weather it is (greater than or equal to condition)
//if both are not working im checking for equal to condition
bool asce=false;
for(int i=0;i<n-1;i++){
if(a[i]<a[i+1]) asce=true;
else {asce=false;break;}
}
if(asce) printf("Ascending");
else{
/////////////////////////////////////////////////
asce=false;
for(int i=0;i<n-1;i++){
if(a[i]<=a[i+1]) asce=true;
else {asce=false;break;}
}
if(asce){
/////////////////////////////////////////////////
equal=false;
for(int i=0;i<n-1;i++){
if(a[i]==a[i+1]) equal=true;
else {equal=false;break;}
}
if(equal) {}
else printf("Not Descding");
}
}
///////////////////////////////////////////////
bool desc=false;
for(int i=0;i<n-1;i++){
if(a[i]>a[i+1]) desc=true;
else {desc=false;break;}
}
if(desc) printf("Desceding");
else{
///////////////////////////////////////////////
desc=false;
for(int i=0;i<n-1;i++){
if(a[i]>=a[i+1]) desc=true;
else {desc=false;break;}
}
if(desc){
/////////////////////////////////////////////////
equal=false;
for(int i=0;i<n-1;i++){
if(a[i]==a[i+1]) equal=true;
else {equal=false;break;}
}
if(equal) {}
else printf("Not Asceding");
}
}
if(equal) printf("EQUAL");
  

return 0;
}

ray length followed by array inputs En 6 1 4 6 8 12 34 Ascending ter ar

Enter array length followed by array inputs 7 1 3 5 9 9 12 17 Not Descding

ray length followed by array inputs En 6 1 4 6 8 12 34 Ascending ter ar

Add a comment
Know the answer?
Add Answer to:
Write a C program that reads a sequence of numbers and display a message 1. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Write a program that reads a sequence of numbers from the keyboard, and displays the...

    1. Write a program that reads a sequence of numbers from the keyboard, and displays the smallest number. The sequence has at least one number and is terminated by -999(-999 will not appear in the sequence other than as the end marker). 2. Write a program which requests an integer input n from the keyboard and computes the sum of square of k for all k from 1 to n(inclusive). use java

  • Write a program that generates 2n Fibinacci numbers. the following is a sequence of Fibinacci numbers:...

    Write a program that generates 2n Fibinacci numbers. the following is a sequence of Fibinacci numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89... (Starting from the third number, the number is the sum of the previous two numbers.)

  • C programing Write a program to sort numbers in either descending or ascending order. The program...

    C programing Write a program to sort numbers in either descending or ascending order. The program should ask the user to enter positive integer numbers one at a time(hiting the enter key after each one) The last number entered by the user should be -1, to indicate no further numbers will be entered. Store the numbers in an array, and then ask the user how to sort the numbers (either descending or ascending). Call a function void sortnumbers ( int...

  • Using c++ Write a program that reads in a list of up to 25 first names...

    Using c++ Write a program that reads in a list of up to 25 first names from an input file nameData.txt and allows the user to display the name data, sort it in ascending or descending order, count the number of occurrences of a given name, or exit the program. The input file consists of a single names per line with each line terminated with an end of line (i.e. using Enter key to end the line). Your program should...

  • Write in C++ program Larger than n In a program, write a function that accepts three...

    Write in C++ program Larger than n In a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume the array contains integers. The function should display all of the numbers in the array that are greater than the number n. Input from the keyboard: The filename and path of a list of integer numbers.                                           The number n to test the file numbers. Output to the console: The...

  • IN JAVA 3 ZIPS, What Order?: Write a program named ZipOrder that the reads in three...

    IN JAVA 3 ZIPS, What Order?: Write a program named ZipOrder that the reads in three zip codes from standard input and prints to standard output one of three words: "ASCENDING", "DESCENDING", "UNSORTED". The zip codes are guaranteed to be distinct from each other. In particular: if each zip code read in is greater than to the previous one, "ASCENDING"  is printed. if each zip code read in is less than to the previous one, "DESCENDING" is printed. otherwise, "UNSORTED" is...

  • 1. Write a program to add positive numbers. Ask the user to enter numbers greater than...

    1. Write a program to add positive numbers. Ask the user to enter numbers greater than zero. If a 0, is entered stop requesting numbers and display the total. If a number is entered that is less than 0, display the message ‘Number must be greater than 0’, then ask for another number to be entered. Repeat until a number greater than 0 or 0 is entered. use math lab so I can copy the answers

  • C++ assignment Write a program that reads a sequence of integers and prints the following: 1....

    C++ assignment Write a program that reads a sequence of integers and prints the following: 1. The number of odd and even numbers of inputs Use a sentinel value to signal the end of inputs. If the sentinel value is the first you enter, give a message “NO input is entered!”. Input Validation: Do not accept a negative number.

  • 6. Consider a C program that reads two real numbers from the keyboard followed by a character where the character can b...

    6. Consider a C program that reads two real numbers from the keyboard followed by a character where the character can be one of the operators +,-, *, 1, or % providing the addition, subtraction, multiplication, division, or remainder respectively. Then the result is displayed on the screen For example, if the user types 2.0 3.0 % then your code will display: Note: In the above example the inputs are real numbers but the remainder only performs an integer operation....

  • Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

    Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT