# C Basic Part-II: Exercises, Practice, Solution

## C Basic-II [7 exercises with solution]

[** An editor is available at the bottom of the page to write and execute the scripts.** Go to the editor]

**1.** Write a C program that takes n number of positive integers. Find the integer that appears the least number of times among the said integers. If there are multiple such integers, select the smallest one.

**Sample Date:**

(1,2,3) -> 1

(10, 20, 4, 5, 11) -> 4

**2.** Write a C program that takes a string and two integers (n1, n2). Now reverse the sequence of characters in the string between n1 and n2.

**Sample Date:**

("abcdxyabcd", 5, 6) -> "abcdyxabcd"

("Exercises", 1, 3) -> "exercises"

**3.** Write a C program that accepts three integers from the user and finds the second largest number among them.

Constraints:

- 1≤ x ≤100
- 1≤ y ≤100
- 1≤ z ≤100

**Sample Date:**

(1 , 2, 3) -> 2

(10, 12, 24) -> 12

(34, 21, 30) -> 30

**4.** Write a C program that accepts two sequences ((a1, a2, .. an), (b1, b2, .. bn)) of integers as input. Find all integers that appear in both sequences, one by one, in ascending order.

Constraints:

- 1≤N1≤100, N1 -> number of integers in first sequence.
- 1≤N2≤100, N2 -> number of integers in second sequence.
- 1 ≤ ai≤ 100 ( 1 ≤ i ≤ N1 )
- 1 ≤ bj≤ 100 ( 1 ≤ j ≤ N2 )

**Sample Date:**

( 1 2 3 1 2 3 4) -> 1 2 3

( 1 2 3 1 2 3) -> 1 2 3

(1 2 3 4 5 6) ->

**5.** Write a C program that accepts a sequence of different values and calculates the sum of the values before and after the maximum value.

The sum of the values before the maximum value is 0, if there are no values before the maximum. Similarly, the sum of the values after the maximum value is 0, if there are no values after the maximum.

**Sample Date:**

1 2 3 -> 3 0

1 2 9 4 5 -> 3 9

2 2 2 2 -> 0 6

**6.** Write a C program that accepts a sequence of positive integers from the user and finds the longest continuous subsequence.

**Sample Date:**

Length of the sequence: 5

Sequence: 5 2 3 4 1

Length of longest ascending contiguous subsequence: 5 [2 3 4]

Length of the sequence: 6

Sequence: 10 20 30 40 50 60

Length of longest ascending contiguous subsequence: 6 [10 20 30 40 50 60]

Length of the sequence: 3

Sequence: 5 1 3

Length of longest ascending contiguous subsequence: 2 [1 3]

**7.** Write a C program that accepts three integers: A, B, and X. Find the smallest absolute value of the difference between X and the integers between A and B.

**Sample Date:**

Input A, B: 7, 11

C: 20

Smallest absolute value of difference between X and integers between A and B (inclusive): 11

Input A, B: 1, 5

C: 4

Smallest absolute value of difference between X and integers between A and B (inclusive): 4

## C programming Code Editor:

**More to Come !**

**Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.**

**It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.**

https://www.w3resource.com/c-programming-exercises/basic-2/index.php

**Weekly Trends and Language Statistics**- Weekly Trends and Language Statistics