Array and Strings – Arithmetic – Problem #3

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: easy

Problem Statement

Write a C program to fill a single dimensional integer array of maximum size 50 with random integral numbers in the range [10, 100] by appropriately calling the rand) library function. User will first enter the number of such random numbers to be generated (maximum 50). Display the array contents. Then, starting with the first (i.e., 0th element in the array), interchange pairs of numbers present at consecutive even positions, only if the first is larger than the second. Count the number of interchanges made. Display the contents of the array after all the interchanges and the number of interchanges. For example, if the original array is [10,9,23,46,34,67,21], then the array alter the interchanges would be [10,9,23,46,21,67,34], number of interchanges =1.

Back to Lab Problems
Array and Strings/Arithmetic/Problem #3

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #3

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.