0% found this document useful (0 votes)
8 views34 pages

questions_for_smvec

The document presents a series of programming tasks involving arrays, digit sums, prime numbers, harmonic numbers, and BMI calculations. Each task includes input and output formats, constraints, sample inputs, and expected outputs, along with C code solutions. The tasks aim to enhance programming skills through practical applications in a variety of mathematical contexts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views34 pages

questions_for_smvec

The document presents a series of programming tasks involving arrays, digit sums, prime numbers, harmonic numbers, and BMI calculations. Each task includes input and output formats, constraints, sample inputs, and expected outputs, along with C code solutions. The tasks aim to enhance programming skills through practical applications in a variety of mathematical contexts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 34

Description:

Janu is good at handleing collection of numbers. For example u give her 2 sets of number list
she gives u the sum of the numbers in a set format ie, addition of array. Her friends wants to
perform the operation regarding the numbers they give. Janu accepted it and does the
addition of the array.

Input Format:
1. Number of rows.
2. Number of columns.
3. Values of the array1.
4. Values of the array2.
5. all should be integers.

Output Format:
Output consists of integer values of Resultant array list.

Constraints:
0<rows,columns<10
0<elements<500

Sample Input:
1
2
14
35

Sample Output:
49

Solution :

#include <stdio.h>

int main() {

int rows, cols;

// Input number of rows and columns

scanf("%d %d", &rows, &cols);

int array1[10][10], array2[10][10], result[10][10];


// Input values for array1

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

scanf("%d", &array1[i][j]);

// Input values for array2

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

scanf("%d", &array2[i][j]);

// Calculate and print the result array

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

result[i][j] = array1[i][j] + array2[i][j];

printf("%d ", result[i][j]);

return 0;

Test cases:

case = t1

input=1
2

output=4 9

case = t2

input=2

output=7 13

13 10

case = t3

input=3

5
45

20

29

30

26

46

56

27

11

39

56

62

74

96

75

82

92

output=16 84 76

91 104 122

121 138 119

case = t4

input=3

101
16

34

46

74

102

18

17

96

34

44

24

102

17

24

44

86

96

76

56

17

28

48

output=203 33 58 90

160 198 94 73
103 51 72 72

case = t5

input=2

100

406

562

321

28

94

62

74

32

47

97

108

output=162 480 594

368 125 202

Question 2:

Ram is small boy. His father gives him a number and ask him to calculate the sum of the digits in that
number till the answer comes in singe digit. As ram is a small boy he doesn't knows how to calculate. So
help him to Find the sum of the digits untill it reaches to single digit.

Input Format:

Input consists of 1 integer.


Output Format:

Output consists of the sum of the digits in the given number

Constraints:

0<number<10^15

Sample Input:

2567

Sample Output:

Solution:

#include<stdio.h>

int main()

int n ;

scanf("%d",&n);

int sum = 0;

while(n > 0 || sum > 9)

if(n == 0)

n = sum;

sum = 0;
}

sum += n % 10;

n /= 10;

printf("%d",sum);

return 0;

Test Cases:

case = t1

input=25678

output=1

case=t2

input=389178

output=9

case=t3

input=589123489

output=4

case=t4

input=314

output=8
case=t5

input=459

output=9

Question 3:

Embark on a journey to the mystical Prime Pyramid Valley, where each row of the pyramid is
adorned with the sacred prime numbers. You, the chosen programmer, have been entrusted
with the task of unveiling the secrets hidden in the patterns of prime numbers.

The Oracle of Prime Pyramid Valley has given you a challenge: Write a C program to print
the prime numbers in a half pyramid pattern. As you ascend each row, reveal the prime
numbers that guard the ancient wisdom. The fate of the valley lies in your coding skills. Can
you craft a program that not only prints the prime numbers but also creates an enchanting
pattern, reflecting the sacred harmony of the Prime Pyramid Valley

Input Format:
Input consists of number of rows to rows to be print.

Output Format:
Output shows the prime prime numbers in half pyramid pattern.

Sample Input:
4

Sample Output:
2
35
7 11 13
17 19 23 29

solution:

#include <stdio.h>

int main() {

int rows;

scanf("%d", &rows);

int num = 2; // Starting with the first prime number


for (int i = 1; i <= rows; i++) {

int count = 0;

while (count < i) {

int is_prime = 1;

for (int j = 2; j * j <= num; j++) {

if (num % j == 0) {

is_prime = 0;

break;

if (is_prime) {

printf("%d ", num);

count++;

num++;

printf("\n");

return 0;

Test cases:

case=t1

input=4
output=2

35

7 11 13

17 19 23 29

case=t2

input=11

output=2

35

7 11 13

17 19 23 29

31 37 41 43 47

53 59 61 67 71 73

79 83 89 97 101 103 107

109 113 127 131 137 139 149 151

157 163 167 173 179 181 191 193 197

199 211 223 227 229 233 239 241 251 257

263 269 271 277 281 293 307 311 313 317

case=t3

input=5

output=2

35

7 11 13

17 19 23 29
31 37 41 43 47

case=t4

input=7

output=2

35

7 11 13

17 19 23 29

31 37 41 43 47

53 59 61 67 71 73

79 83 89 97 101 103 107

case=t5

input=9

output=2

35

7 11 13

17 19 23 29

31 37 41 43 47

53 59 61 67 71 73

79 83 89 97 101 103 107

109 113 127 131 137 139 149 151

157 163 167 173 179 181 191 193 197

Question 4:
Imagine you are an apprentice in the kingdom of Harmonica, where the mystical Harmonic
Numbers hold the key to unlocking the secrets of harmonic resonance. The Harmonic King
has set forth a quest for you to unveil the harmonic patterns that lie hidden in the square of
wisdom.

Your task is to write a C program that crafts a square pattern using the magical Harmonic
Numbers. As you traverse the rows and columns, reveal the harmonic fractions that
resonate with the energies of the kingdom. Can you, the chosen programmer, decipher the
harmonic square pattern and harness the harmonious frequencies encoded within, thereby
unlocking the ancient wisdom of Harmonica?

Input Format:
Input consists of size of the square (no.of rows and columns)

Output Format:
Output shows the harmonic number in square pattern.

Sample Input:
3

Sample Output:
1\1 1\2 1\3
1\4 1\5 1\6
1\7 1\8 1\9

Solution:

#include &lt;stdio.h&gt;

int main()

int n;

scanf(&quot;%d&quot;, &amp;n);

int count = 1;

for (int i = 1; i &lt;= n; i++) {

for (int j = 1; j &lt;= n; j++) {

if (count &lt;= n * n) {

printf(&quot;1/%d\t&quot;, count);
count++;

} else {

break;

printf(&quot;\n&quot;);

return 0;

Test cases:

case=t1

input=3

output=1\1 1\2 1\3

1\4 1\5 1\6

1\7 1\8 1\9

case=t2

input=5

output=1\1 1\2 1\3 1\4 1\5

1\6 1\7 1\8 1\9 1\10

1\11 1\12 1\13 1\14 1\15

1\16 1\17 1\18 1\19 1\20

1\21 1\22 1\23 1\24 1\25


case=t3

input=7

output=1\1 1\2 1\3 1\4 1\5 1\6 1\7

1\8 1\9 1\10 1\11 1\12 1\13 1\14

1\15 1\16 1\17 1\18 1\19 1\20 1\21

1\22 1\23 1\24 1\25 1\26 1\27 1\28

1\29 1\30 1\31 1\32 1\33 1\34 1\35

1\36 1\37 1\38 1\39 1\40 1\41 1\42

1\43 1\44 1\45 1\46 1\47 1\48 1\49

case=t4

input=2

output=1\1 1\2

1\3 1\4

case=t5

input=9

output=1\1 1\2 1\3 1\4 1\5 1\6 1\7 1\8 1\9

1\10 1\11 1\12 1\13 1\14 1\15 1\16 1\17 1\18

1\19 1\20 1\21 1\22 1\23 1\24 1\25 1\26 1\27

1\28 1\29 1\30 1\31 1\32 1\33 1\34 1\35 1\36

1\37 1\38 1\39 1\40 1\41 1\42 1\43 1\44 1\45

1\46 1\47 1\48 1\49 1\50 1\51 1\52 1\53 1\54

1\55 1\56 1\57 1\58 1\59 1\60 1\61 1\62 1\63

1\64 1\65 1\66 1\67 1\68 1\69 1\70 1\71 1\72


1\73 1\74 1\75 1\76 1\77 1\78 1\79 1\80 1\81

Question 5:

Imagine a futuristic world where a secret society of health enthusiasts has discovered a
hidden formula for unlocking the mysteries of well-being. You, a brilliant programmer, have
been chosen to decipher the code that lies within the Body Mass Index (BMI) – the key to
understanding one's health.

In this quest, you find a mysterious ancient device that prompts users to input their weight
and height. As you decipher the BMI algorithm, you unveil a magical number that holds the
secret to an individual's physical condition. Your mission is to write a C program that
calculates the BMI, providing a glimpse into the user's well-being.

Input Format:
Input consists of weight and height of a person in floating point.
1. weight of a person in kilogram.
2. height of the person in Centimeter.

Output Format:
1st shows the BMI of the person(correct it to 2 decimal places)
2nd prints the fitness condition of the person whether he/she is Normal weight, under weight
or obese.

Sample Input:
99
151

Sample Output:
43.42
Obese

Solution:

#include <stdio.h>

int main() {

float weight, height;

// Input weight in kg and height in cm

scanf("%f %f", &weight, &height);


// Convert height to meters

height = height / 100;

// Calculate BMI

float bmi = weight / (height * height);

// Print BMI to 2 decimal places

printf("%.2f\n", bmi);

// Determine fitness condition

if (bmi < 18.5) {

printf("Underweight\n");

} else if (bmi >= 18.5 && bmi <= 24.9) {

printf("Normal weight\n");

} else {

printf("Obese\n");

return 0;

Test cases:

case=t1

input=99
151

output=43.42

Obese

case=t2

input=50.6

161

output=19.52

Normal weight

case=t3

input=43

172

output=14.53

Underweight

case=t4

input=66.6

121

output=45.49

Obese

case=t5

input=40

134.5
output=22.11

Normal weight

Question 6 :

Once upon a time, in a quaint village, there was a mystical array that held the key to the
prosperity of the entire community. Legends spoke of an ancient algorithm, known only to a
few, that could rearrange the elements of this magical array in a peculiar way.

The village was facing a dilemma, and the elders believed that if they could rearrange the
array by placing elements at odd indices to even indices and vice versa, the hidden powers
within the array would bring about abundance and good fortune to the villagers.

Your task is to write a Java program to unlock the magic of the array. The villagers have
handed you the array, and you must create a program that performs the mysterious swap,
turning the ordinary array into an extraordinary source of prosperity for the entire village.

Can you decipher the ancient algorithm and bring prosperity to the village by rearranging
the elements of the mystical array?

Input Format:
An integer that indicates the number of elements in the array.
elements of array in integer.

Output Format:
Shows the rearranged array.

Constraints:
The size of the array should be greater than 1.

Sample Input:
5
2
4
5
6
3

Sample Output:
42653

Solution:

#include <stdio.h>

int main() {
int n;

// Input the number of elements in the array

scanf("%d", &n);

if (n <= 1) {

printf("Array size must be greater than 1\n");

return 1;

int arr[n];

// Input the elements of the array

for (int i = 0; i < n; i++) {

scanf("%d", &arr[i]);

// Swap elements at odd indices with even indices

for (int i = 1; i < n; i += 2) {

int temp = arr[i];

arr[i] = arr[i - 1];

arr[i - 1] = temp;

// Print the rearranged array


for (int i = 0; i < n; i++) {

printf("%d ", arr[i]);

return 0;

Testcases:

case=t1

input=5

output=4 2 6 5 3

case=t2

input=0

output=Invalid size for the array.

case=t3

input=8

42

65
88

90

97

67

75

output=65 42 90 88 67 97 75 5

case=t4

input=1

output=Invalid size for the array.

case=t5

input=10

90

65

45

36

98

100

345

93

output=7 6 65 90 36 45 100 98 93 345


Question 7:

In a mystical land, there were five wizards, each possessing a magical ring. These rings were
said to have special powers when their GCD (Greatest Common Divisor) was found. The
wizards decided to embark on a quest to uncover the combined magic within their rings.

The ancient scrolls spoke of a legendary algorithm hidden within the enchanted forest that
could reveal the GCD of any set of magical numbers. As a skilled programmer, you were
chosen to write a program that would unlock this mystical power.

Your task is to create a C program that takes the magical numbers from the wizards, finds
their GCD, and unveils the true potential of their rings. Can you decipher the ancient
algorithm and unleash the magical energy stored within the rings?

Input Format:
1. Enter the size of the array in integer(it is positive integer)
2. enter the elements of array.

Output Format:
Output prints the GCD of the array.

Sample Input:
4
15
25
35
45

Sample Output:
5

Solution:

#include <stdio.h>

int main() {

int n;

// Input the size of the array

scanf("%d", &n);
if (n <= 0) {

printf("Invalid array size\n");

return 1;

int arr[n];

// Input the elements of the array

for (int i = 0; i < n; i++) {

scanf("%d", &arr[i]);

// Function to calculate GCD of two numbers

int gcd = arr[0];

for (int i = 1; i < n; i++) {

int a = gcd, b = arr[i];

while (b != 0) {

int temp = b;

b = a % b;

a = temp;

gcd = a;

}
// Print the GCD of the array

printf("%d\n", gcd);

return 0;

Testcases:

case=t1

input=4

15 25 35 45

output=5

case=t2

input=3

24 36 48

output=12

case=t3

input=5

10

30

50

80

60

output=10
case=t4

input=1

27

output=27

case=t5

input=0

output=Invalid array size

Question 8:

In the mystical land of Numerica, there existed a legendary puzzle known as the "Neon
Enigma." It was said that only numbers possessing a unique glow, known as "neon
numbers," could unlock the secrets hidden within the enchanted realm.

You, as the chosen one, embarked on a journey to decipher the Neon Enigma. Guided by an
ancient prophecy, you must develop a magical program that reveals whether a given
number carries the radiant essence of a neon number.

The Oracle of Numerica provided you with a clue: "When the sum of the digits of a number,
squared, mirrors the number itself, the glow of a neon number is revealed."

Can you craft a C program to uncover the neon numbers and unveil the mysteries of the
Neon Enigma?

Input Format:
Enter a positive integer number.

Output Format:
Output prints "Neon Number" or "Not a Neon Number"

Sample Input:
16
Sample Output:
Not a Neon Number

solution:

#include <stdio.h>

int main() {

int num, sum_of_digits = 0;

// Input the number

scanf("%d", &num);

if (num <= 0) {

printf("Not a Neon Number\n");

return 1;

// Calculate the square of the number

int square = num * num;

// Calculate the sum of the digits of the square

while (square > 0) {

sum_of_digits += square % 10;

square /= 10;

// Check if the sum of digits equals the original number


if (sum_of_digits == num) {

printf("Neon Number\n");

} else {

printf("Not a Neon Number\n");

return 0;

Testcases:

case=t1

input=16

output=Not a Neon Number

case=t2

input=9

output=Neon Number

case=t3

input=25

output=Neon Number

case=t4

input=12

output=Not a Neon Number


case=t5

input=0

output=Neon Number

Question 9:

In the enchanting land of Linguatopia, a mystical figure known as the "Word Weaver"
possessed the extraordinary ability to manipulate words with magical precision. Legends
spoke of an ancient artifact called the "Numeralbane," capable of removing numbers from
any word it touched.

As the chosen apprentice, your quest is to craft a magical program to emulate the powers of
the Numeralbane. Armed with a keyboard and your coding incantations, you embark on this
journey.

The Elders of Linguatopia guide you: "Create a C program that removes the numbers from a
single word, unleashing the true essence of linguistic magic."

Can you harness the power of the Numeralbane and become the Word Weaver's true
successor?

Input Format:
Enter a word with numbers as input.

Output Format:
Output shows the word without the numbers.

Sample Input:
A1r5u8n

Sample Output:
Arun

Solution:

#include <stdio.h>

int main() {

char word[100], result[100];

int index = 0;
// Input the word with numbers

scanf("%s", word);

// Process the word to remove numbers

for (int i = 0; word[i] != '\0'; i++) {

if (word[i] < '0' || word[i] > '9') {

result[index++] = word[i];

// Null-terminate the result string

result[index] = '\0';

// Output the word without numbers

printf("%s\n", result);

return 0;

Testcases:

case=t1

input=A1r5u8n

output=Arun
case=t2

input=hell122o3worl4d

output=helloworld

case=t3

input=1e2leph4an5t

output=elephant

case=t4

input=123wo4r4l5d5of4c

output=worldofc

case=t5

input=h2a3i4ho5w2a4r5e8y0o8u

output=haihowareyou

Question 10:

In the futuristic city of Codeopolis, a brilliant scientist named Dr. Quantum has developed a
groundbreaking invention called the "Time-Shift Array." This array has the astonishing ability
to rearrange itself and remove specific elements across time.

As a keen explorer of code and technology, you receive a mysterious message from Dr.
Quantum, challenging you to create a program that utilizes the Time-Shift Array. Your
mission is to reverse the array and eradicate any remnants of numbers divisible by 2(even
number).

Embrace the challenge, dear coder, and embark on a journey through the temporal currents
of Codeopolis. Will you successfully manipulate the Time-Shift Array and unveil the future of
numeric sequences?

Input Format:
1st line contains the size of the array
from second line type the elements of array
Output Format:
Output shows the resultant array after reversing and removing of all even numbers

Sample Input:
3
12
33
55

Sample Output:
55 33

Solution:

#include <stdio.h>

int main() {

int n;

scanf("%d", &n); // Read the size of the array

int arr[n]; // Declare the array of size n

// Read the elements of the array

for (int i = 0; i < n; i++) {

scanf("%d", &arr[i]);

// Reverse and remove even numbers

for (int i = n - 1; i >= 0; i--) {

if (arr[i] % 2 != 0) { // If the number is odd

printf("%d ", arr[i]); // Print the number


}

return 0;

Testcases:

case=t1

input=3

12

33

55

output=55 33

case=t2

input=5

output=5 3 1

case=t3

input=6
2

44

88

90

output=

case=t4

input=4

19

37

55

output=55 37 19

case=t5

input=7

23

32

44

57

567

445

output=3 445 567 57 23

You might also like