SET A - Coding Questions - EASY - VVCE
SET A - Coding Questions - EASY - VVCE
Program 1
The function accepts 2 positive integer ‘m’ and ‘n’ as its arguments.You are required to calculate the sum of
numbers divisible both by 3 and 5, between ‘m’ and ‘n’ both inclusive and return the same.
Note:
0 < m <= n
Example
Input:
m : 12
n : 50
Output
90
Explanation:
The numbers divisible by both 3 and 5, between 12 and 50 both inclusive are {15, 30, 45} and their sum is 90.
Sample Input
m : 100
n : 160
Sample Output
405
• Case 1
Input (stdin)
12
50
Output (stdout)
90
1
• Case 2
Input (stdin)
20
30
Output (stdout)
30
#include<iostream>
using namespace std;
Program 2
2
Table of Numbers
Write a program to display the table of a number and print the sum of all the multiples in it.
Test Cases:
Test Case 1:
Input:
5
Expected Result Value:
5 10 15 20 25 30 35 40 45 50
275
Test Case 2:
Input:
12
Expected Result Value:
12 24 36 48 60 72 84 96 108 120
660
• Case 1
Input (stdin)
12
Output (stdout)
12 24 36 48 60 72 84 96 108 120
660
• Case 2
Input (stdin)
5
Output (stdout)
5 10 15 20 25 30 35 40 45 50
275
#include <iostream>
using namespace std;
int main()
{
int n, i, value=0, sum=0;
cin>>n;
for(i=1; i<=10; ++i)
3
{
value = n * i;
cout<<value<<" ";
sum=sum+value;
}
cout<<endl<<sum ;
return 0;
}
Program 3
4
Instructions: You are required to write the code. You can click on compile and run anytime to check
compilation/execution status. The code should be logically/syntactically correct.
Question: Write a program in C such that it takes a lower limit and upper limit as inputs and print all the
intermediate pallindrome numbers.
Test Cases:
TestCase 1:
Input :
10 , 80
Expected Result:
11 , 22 , 33 , 44 , 55 , 66 , 77.
Test Case 2:
Input:
100,200
Expected Result:
101 , 111 , 121 , 131 , 141 , 151 , 161 , 171 , 181 , 191.
#include<stdio.h>
int main()
{
int i, n, reverse, d,f,l;
printf("enter the starting \n",f);
scanf("%d",&f);
printf("enter the ending\n",l);
scanf("%d",&l);
for (i = f; i <= l; i++)
{
reverse = 0;
n = num;
while (n != 0)
{
d = n % 10;
reverse = reverse * 10 + d;
n = n / 10;
}
if (i == reverse)
printf("%d ",i);
}
return 0;
}
Program 4
5
Instructions: You are required to write the code. You can click on compile & run anytime to check the
compilation/ execution status of the program. The submitted code should be logically/syntactically correct and
pass all the test cases.
Ques: The program is supposed to calculate the distance between three points.
For
x1 = 1 y1 = 1
x2 = 2 y2 = 4
x3 = 3 y3 = 6
Distance is calculated as : sqrt(x2-x1)2 + (y2-y1)2
#include <stdio.h>
#include <math.h>
int main()
{
int t;
float p1[2], p2[2], p3[2];
printf("enter x1 and y1 : ");
scanf("%f%f",&p1[0],&p1[1]);
printf("enter x2 and y2 : ");
scanf("%f%f",&p2[0],&p2[1]);
printf("enter x3 and y3 : ");
scanf("%f%f",&p3[0],&p3[1]);
t = isDistance(&p1, &p2, &p3);
printf("%d",t);
return 0;
}
6
Program 5
Operation Choices
You are required to implement the following function.
int OperationChoices(int c, int a, int b )
The function accepts 3 positive integers ‘a’ , ‘b’ and ‘c ‘ as its arguments. Implement the function to return.
( a+ b ) , if c=1
( a - b ) , if c=2
( a * b ) , if c=3
(a / b) , if c =4
Assumption: All operations will result in integer output.
Example:
Input
c:1
a:12
b:16
Output:
Since ‘c’=1, (12+16) is performed which is equal to 28, hence 28 is returned.
Sample Input
c: 2
a: 16
b: 20
Sample Output
-4
• Case 1
Input (stdin)
2
16
20
Output (stdout)
-4
• Case 2
Input (stdin)
1
12
16
Output (stdout)
28