[Please follow the input and output formats according the sample inputs and outputs written with every questions]
-
Update the following code such that it swaps the contents of two two variables. You can only write code inside the two comments. Do not modify anything else. The printf function is supposed to print “13 and 5”. So basically the value must be swapped but you can not assign 13 directly to a and 5 directly to b. You can not use other numbers as well. But you can declare an extra variable if you need.
int a=5, b=13;
//Write code here
//End of code
printf(“%d and %d” , a, b); -
You need to take 4 distinct integer as input. Print the largest and smallest among them. Distinct means all of them are separate integers. None of them is equal to any other of them.
Sample Input:
123 435 34 612Sample Output:
Largest = 612
Smallest = 34 -
You will be given a number as input. You will have to find the number of digits in that number. You will have to use loops to solve this problem as the input can have any number of digits. [Hint: Use the modulus operator. You can extract last digit from any number by using %10 operation on the number.]
For example,
Sample Input:
2346167Sample Output:
7 digitsSince the input had 7 digits so the output is 7. Please use long long int as data type for this problem.
-
This time you need to find the sum of the digits of the input. So look at the sample input output.
Sample Input:
2346167Sample Output:
29 Explanation: Since, the sum of the digits is 2+3+4+6+1+6+7 = 29. So the output is 29. -
Let us create a new version of weird algorithm. You will be given an integer, n as input. If n is even, divide it by two. If n is odd, then subtract 1 from n. Eventually it will end at 1. So print the whole sequence. For example,
Sample Input:
123Sample Output:
123, 122, 61, 60, 30, 15, 14, 7, 6, 3, 2, 1Follow the whole output format(each numbers separated by commas).
-
Write a C program that will take two integers as input from you. And then it will show us in output whether any one of those two numbers is divisible by the other or not.
Sample Input 1:
Enter the first number: 13
Enter the second number: 39Sample Output 1:
The second number is divisible by the first number.Sample Input 2:
Enter the first number: 38
Enter the second number: 13Sample Output 2:
None of them are divisible by the other. -
Take two integers as input and print their GCD as the output. We know, GCD of two numbers is the greatest common divisor of two numbers. You can use the logic from Question no. 6 to solve this problem.
Sample Input 1:
12 18Sample Output 1:
The GCD of 12 and 18 is 6.Explanation:
Since 6 is the largest number which divides both 12 and 18 so 6 is output. -
Take two integers as input and print their LCM as the output. We know, LCM of two numbers is the least common multiple of two numbers. You can use the logic from Question no. 6 to solve this problem.
Sample Input 1:
12 18Sample Output 1:
The LCM of 12 and 18 is 36.Explanation:
Since 36 is the least number which is divisible by both 12 and 18 so 36 is the output. -
Write a C program to print all the factors of a number taken as input.
Sample Input 1:
12Sample Output 1:
The factors of 12 are: 1, 2, 3, 4, 6, 12.Sample Input 2:
39Sample Output 2:
The factors of 39 are: 1, 3, 13, 39. -
Primality Testing is one of the most common and the most important problem in the world of Number Theory and also in basic programming. In this problem you will be given an integer as input and you need to find out whether the number is prime or not. Just for your information, prime numbers are the numbers that have only two factors which are 1 and themselves. For example, 37 is a prime number because it has no factors other than 1 and 37. On the other hand 39 is not a prime number called composite number since 39 has factors other than 1 and 39 such as 3 and 13.
Sample Input 1:
12Sample Output 1:
CompositeSample Input 2:
1009Sample Output 2:
Prime
Given the sum of four numbers and three of those numbers, find the missing number. All four numbers are positive integers.
- The first line will contain T, number of test cases.
- For every test case, the input will contain one integer S (the sum of the four numbers), A, B, C (three of those four numbers).
- 0 < T <= 100
- 0 <= S, A, B, C <= 2^32
Print the missing number. Don't forget to print a new line after printing the value.
1
10 1 2 3
4
Alien Cricket Board has decided to throw out a player out of the team if his performance is very bad against a match against Bangladesh team. If any player is not able to make at least K runs he will be out of the team. You will be given N, the number of players and the runs that the players were able to take and K, the minimum run that every player needs to take to be in the team. Can you tell the number of players that will be out of the team?
- First line will contain N and K
- Second line will contain N values, the runs that the players have taken
1 <= N <= 100
0 <= K <= 100
0 <= Run <= 100
Output the number of players that will be thown out of the Alien team
Sample Input 0
5 10
100 25 0 9 10
Sample Output 0
2
Explanation 0
As 2 player could not score at lease 10 runs, the answer is 2.
We have learned how to print patters in C language. This time you will have to print a different type of pattern of numbers. Look at the output to understand the pattern. You will have to write a C program that will take an integer number and creates similar patters for the corresponding inputs.
You will be given a positive integer N as input.
1 <= N <= 20
Output Format
Output the pattern
Sample Input 0
5
Sample Output 0
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
Sample Input 1
4
Sample Output 1
1 2 1 3 2 1 4 3 2 1
There are N students in a class. Recently they got their Math course marks. One of them got the highest marks. So now they want to know how much more marks they need to get the highest mark. Can you calculate for every student what is the difference between their marks and the highest marks and print them!
- First line will contain N
- Second line will contain the marks of N students
1 <= N <= 100
0 <= Marks <= 100
Output Format
Output the difference between the marks of any student and highest marks
Sample Input 0
5
15 25 50 24 48
Sample Output 0
35 25 0 26 2
One day Bablu went to the supermarket to buy a new phone. He was eagerly waiting for the launch of the Alien phone. It has a 15000 mAh battery. Finally he bought it! The salesman told him that, if the charge is _less than 60% then it will take 1 minute to charge for every 1%. If the charge is less than 80% then it will take 2 minute to charge for every 1%. And finally from 80% it will take 3 minutes to charge 1%.
Now he wants to calculate if the current charge is X% then how many minutes it will take to charge completely. Can you calculate for him?
- The first line will contain an integer T, the number of test case.
- For every test case, one line will contain an integer X, current percentage of charge in the battery.% sign will also given as input
- 1 <= T <=101
- 0 <= X <= 100
Output a single line for every test case, how many minutes it will take to charge completely and print "minutes" after it. Don't forget to put a new line after it.
Sample Input 0
5
35%
88%
0%
100%
68%
Sample Output 0
125 minutes
36 minutes
160 minutes
0 minutes
84 minutes
Explanation 0
For the first test case, from 35% to 60% it will take 25 minutes. From 60% to 80% it will take 40 minutes and from 80% to 100% it will take 60 minutes. In total 25+40+60=125 minutes.
Noman is a social worker. He wants to keep his documents secret. That's why he has bought a safe with him in his house. Now he wants to put a secret code into the safe. He was thinking that a number N would be a good secret code if no other number except 1 and N can divide that number. So, he was thinking of some numbers, can you help him to find the one he was looking for?
- The first line will consist of T, the number of test cases.
- The next T lines will contain a number N, the secret code that Noman was thinking.
- 0 < T <= 100
- 0 < N <= 10^5
Ouput "Yes" if the number could be a secret code, otherwise "No" without the quotation. Put a new line after
Sample Input 0
5
73
35
92
1
60
Sample Output 0
Yes
No
No
No
No
English teacher Mr. Rahim of class Ten asked for the homeworks of the students. Class captain has collected all the notebooks and put them in table. But the class captain put the notebooks of girls first, and then the notebooks of the boys. So Mr. Rahim asked the captain to keep the boy's notebooks to the left side and then the girl's notebooks. If the last index (index starts from 1) of a girl's notebook is K then can you print them in the right order? Note: If K is 0, that means there is no girl's notebook.
- First line will contain N, the number of students in that class
- Second line will contain Roll of the students
- Third line will contain K, the last index of a girl's notebook
- 1 <= N <= 20
- 1 <= Roll <= 20
- 0 <= K <= 20
Output the rolls of the students in the right order that class teacher wants.
Sample Input 0
10
2 4 5 1 6 12 10 14 3 19
5
Sample Output 0
12 10 14 3 19 2 4 5 1 6
Phitron planned to throw a party for the students. In the party we found that N students are present. However, as a formality we asked each student to shake hands with each other student. You will have to count the number of unique hand-shakes in that party. N will be an input in your C program and the total number of hand-shakes will be the output. Look at the sample input and outputs for clarification
For example, if N=4 then total unique handshakes will be 6.
- 1 with 2
- 1 with 3
- 1 with 4
- 2 with 3
- 2 with 4
- 3 with 4
- You will be given a positive integer N
- 1 <= N <= 10^9
Output the count of unique hand shakes
Sample Input 0
5
Sample Output 0
10
Sample Input 1
17
Sample Output 1
136
You are given a string S consisting only +(Addition),*(Multiplication). The next line will contain two positive values.
Now, Calculate the sum of every operations. See the explanation for more clarification.
First line contains a string S_, consisting only +(Addition),*(Multiplication)_ operator.
The second line will contain two positive integers a and b
- 1<= |S| <= 20, where |S| means the length of S.
- 1<= a, b <= 50
Print the summation which were perform based on String S.
+*
5 10
65
- when S[i] = '+',Then a+b = 5 + 10 = 15 and sum = 15
- when S[i] = '',Then ab = 5 * 10 = 50 and sum = 15 + 50 = 65
+***+
2 1
12
A palindrome is a word whose spelling is the same when we spell it from forward or backward. Your task is to print the word in the given condition:
- Case #1: If a word is not a palindrome, then just print “Not Palindrome” without quotations.
- Case #2: If the word is a palindrome and the word is too long if its length is strictly more than 7 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: We will write down the first and the last letter of a word and between them - we will write the number of letters between the first and the last letters. That number is in the decimal system and doesn't contain any leading zeroes. Thus, "mmmmmabbammmmm" will be spelled as "m12m".
- Case #3: If the word is plaindrome and its length is less than or equal 7 characters.Then, just print the word.
The first line contains an integer T (1 ≤ T ≤ 20).
Each of the following T lines contains one word S. Where, all the letters are lowercase and possess the lengths of from 1 to 20 characters.
- 1 <= T <= 20
- 1 <= |S| <= 20, Here |S| means the length of S.
Output as per the instructions given in the question. Also print which case it belongs to from the given 3 cases. See the sample output for more clarification.
4
madam
mmmmmaaaaammmmm
programminghero
phitron
Case #3: madam
Case #2: m13m
Case #1: Not Palindrome
Case #1: Not Palindrome
A matrix is a 2D array of numbers arranged in rows and columns. We give you a Matrix of N rows and M columns.
Now your task is to do this operation on this matrix:
- If the value matches with the current row and column number then add 3 with the value.
- If the value matches with only the current row number then add 2 with the value.
- If the value matches with only the current column number then add 1 with the value.
- The first line contains N is the number of rows in this matrix and M is the number of columns in this matrix
- The second line contains a 2D array Arr[i][j].
- 1 <= N, M <= 10
- 0 <= Arr[i][j] <= 100
Print the matrix after the operation is done.
3 3
1 1 1
1 1 1
1 1 1
4 3 3
2 1 1
2 1 1
In this sample input,
When row=1 and column=1 also value of this location is 1, So we add 3 to this value after this operation the value of this location is 4.
When row=1 and column=2 also value of this location is 1 which match with the row only, So we add 2 to this value after this operation the value of this location is 3.
When row=2 and column=1 also value of this location is 1 which match with the column only, So we add 1 to this value after this operation the value of this location is 2.
So this way we check all value row and column then do the operation.