Question

16.14 Lab 5: a Name your program sorted.c - The purpose of this program is to...

16.14 Lab 5: a

Name your program sorted.c - The purpose of this program is to read in a series of integers via command line arguments and then determine if this set of integers is sorted in ascending order. You will output the first number's index in argv that causes the set to not be sorted. For example:

Input: ./a.out 1 2 3 4 5 10 15 20 21 23 500 -2 501 505
Output: Unsorted at 12 index.
Input: ./a.out 26 27 29 30 31 32 45 46 47 101 134 138
Output: Sorted.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The solution of the above question can be given as below:

/*Program Screen Shot */

/*Output Screen Shot */

/*Source Code */

#include <stdio.h>
#include <stdlib.h>


int main(int argc,char* argv[]) {
    int array[argc];
    
    /*Converting String Values to Integers */
    for(int i=1;i<=argc;i++){
        array[i] = atoi(argv[i]);
    }
    
    for (int i=1;i<argc-1;i++){
        /*If elements not found in sorted order */
        if(array[i+1] < array[i]){
            printf("Unsorted at %d index.", (i+1));
            exit(EXIT_SUCCESS);
        }
    }
    /*If elements are in sorted order */
    printf("Sorted");
    return 0;
}

---------------------------------------------------------------------------------------------------------------------------------

Please like the post and comment for any query related to the problem.

Thanks for liking the post !

Add a comment
Know the answer?
Add Answer to:
16.14 Lab 5: a Name your program sorted.c - The purpose of this program is to...
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
  • in c prog only please!! Name this program one.c - This program takes two command line...

    in c prog only please!! Name this program one.c - This program takes two command line arguments: 1. an input filename 2. a threshold Your program will create two files: 1. even.txt - contains all integers from the input file that are even and greater than the threshold 2. odd. txt - contains all integers from the input file that are odd and greater than the threshold • The input file will exist and only contain a set of integers....

  • Below is the picture for the direction of my program and also the part where I...

    Below is the picture for the direction of my program and also the part where I have problems with I've already finished it and my code works correctly. But what I need to do is to "read the file name from the command line arguments" instead of the standard input (cin) that I did for step 1. I'm not sure how to do that. 2.13 PROGRAM 1: Calculating Coefficient Of Lift For this PROGRAM you will calculate the coefficient of...

  • Programming in C. Name this program schwifty.c - This program reads a text file and makes...

    Programming in C. Name this program schwifty.c - This program reads a text file and makes it schwifty, but the user determines the schwiftiness. The user supplies the filename to schwift and a string containing a sequence of the following characters to determine the schwiftiness via command line arguments: L - Left shift each character in a word: hello --> elloh R - Right shift each character in a word: elloh --> hello I - Shift the letters' and digits'...

  • Written in Java Your job is to produce a program that sorts a list of numbers...

    Written in Java Your job is to produce a program that sorts a list of numbers in ascending order. Your program will need to read-in, from a file, a list of integers – at which point you should allow the user an option to choose to sort the numbers in ascending order via one of the three Sorting algorithms that we have explored. Your program should use the concept of Polymorphism to provide this sorting feature. As output, you will...

  • a. You have 5 problems in this assignment. b. G++ compiler will be used to compile...

    a. You have 5 problems in this assignment. b. G++ compiler will be used to compile your source codes. c. Your program will be tested on Ubuntu 16.04. d. You are not allowed to use global variables in your implementation. e. Your program will get two arguments, input and output file names, from the command line: >> Your_Executable INPUT_FILE_NAME OUTPUT_FILE_NAME 1. Given a number ? , we initially have ?+1 different sets which are {0}, {1}, {2}, ... , {?}....

  • C PROGRAM, A FOPEN FILE NEED TO BE CREATED Objective To review reading from a file....

    C PROGRAM, A FOPEN FILE NEED TO BE CREATED Objective To review reading from a file. To use records (an instance of a struct) To use Dynamic Memory Allocation To create and use a dynamically allocated array of structs To use enumerated types in a useful manner (more info given on Discussion board!) The Problem Bad economic times has forced the UCF administration to think outside the box for alternative methods of income. Specifically, we now have a UCF lottery,...

  • Project Description: In this project, you will combine the work you’ve done in previous assignments to...

    Project Description: In this project, you will combine the work you’ve done in previous assignments to create a separate chaining hash table. Overview of Separate Chaining Hash Tables The purpose of a hash table is to store and retrieve an unordered set of items. A separate chaining hash table is an array of linked lists. The hash function for this project is the modulus operator item%tablesize. This is similar to the simple array hash table from lab 5. However, the...

  • Program Description You are going to write a C++ program to manage toy salesmen. A salesman's...

    Program Description You are going to write a C++ program to manage toy salesmen. A salesman's data is updated periodically with sales and the time over which the money was collected. When requested, it returns sales per hour. A salesman can be updated many times before his/her sales per hour are requested, so the data needs to be accumulated. When the sales per hour are requested, the sales per hour are calculated and the salesman's accumulated data are set back...

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