Ex No 3
Ex No 3
Constraints:
1 <= A, B, and C <= 50
Input Format:
Only line of input has three integers A B C separated by a space.
Output Format:
Print the output in a single line If the given triple is poor, print Yes; otherwise,
print No.
#include <stdio.h>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if ((a == c && b != c) || (b == c && c != a)) {
printf("Yes");
}
else {
printf("No");
}
return 0;
}
2
Problem Description:
In primary mathematics classes, you all have learned about profit and loss.
If cost price is greater than selling price, then there is a loss otherwise profit
Constraints:
1000≤cp≤45000
1000≤sp≤45000
Input Format:
First Line : Integer representing the Cost price
Second Line: Integer representing Selling Price
Output Format:
If Cost Price > Selling Price Print a “Loss” along with the amount of loss.
If Cost Price < Selling Price Print as "Profit" along with the amount of profit.
If Cost Price = Selling Price Print “No Profit No Loss”
#include <stdio.h>
int main() {
int cp, sp, amt;
scanf("%d", &cp);
scanf("%d", &sp);
if (sp > cp) {
amt = sp - cp;
printf("Profit: %d", amt);
}
else if (cp > sp) {
amt = cp - sp;
printf("Loss: %d", amt);
}
else {
printf("No Profit No Loss");
}
return 0;
}
3
Can you help them with the order in which they have to sit if the number of
rows is given by the professor?
Constraints:
1 ≤ no of rows in class ≤ 15
Input Format:
The only line of input has a single integer representing the number of rows in
which students have to sit.
Output Format:
Print the seating layout in a triangular-shaped class according to the number
of rows.
Instruction: To run your custom test cases strictly map your input and output
layout with the visible test cases.
#include <stdio.h>
int main() {
int noofrowsinclass;
int i;
int j;
scanf("%d", &noofrowsinclass);
for (i = 1; i <= noofrowsinclass; i++) {
for (j = 1; j <= i; j++) {
if (i % 2 == 0)
printf("Fail ");
else
printf("Pass ");
}
printf("\n");
}
return 0;
}
4
Problem Description:
Fazil frequently uses Hexadecimal notation in his work.
Constraints:
Each X and Y is A, B, C, D, E or F.
Input Format:
The input is given from Standard Input in the following format: X Y
Output Format:
If X is smaller, print <; if Y is smaller, print >; if they are equal, print =.
#include <stdio.h>
int main() {
char X, Y;
scanf("%c %c",&X,&Y);
if (X > Y) {
printf(">");
}
else if (X < Y) {
printf("<");
}
else if (X == Y)
printf("=");
return 0;
}
5
Problem Description:
Agathiyan is the Chief In charge for carrying out World Economic Survey in
India.
As a part of survey his team have collected the salaries of the citizens of India.
Now Agathiyan would like to classify the earnings of the citizen based on the
number of digits of his/her salary into 5 different categories as follows:
1.Insufficient Earning
2.Very Low Earning
3.Low Earning
4.Sufficient Earning
5.High Earning
Can you help him do the above classification if he gives the salary of the
particular person to you as input?
Constraints:
0≤N≤1000000
Input Format:
Only line of input will contain the number N.
Output Format:
Print "Insufficient Earning" if N is a 1 digit number.
Print "Very Low Earning" if N is a 2 digit number.
Print "Low Earning" if N is a 3 digit number.
Print "Sufficient Earning" if N has more than 4 digits.
Print "High Earning" if N has more than 4 digits.
}
Problem Description:
Today is Caleb's birthday. His dad has surprised him with truly fruity gifts: 2
fruit baskets. The first basket contains N Avacados, and the second one
contains M dragon fruits. Caleb likes Avacados and Dragon fruits very much
but he likes them equally, and therefore, wants to have the minimum possible
difference between the number of Avacados and Dragon fruits he has. To do so,
he can purchase 1 Avacado or 1 Dragon fruit by paying exactly 1 gold coin
(that's some expensive fruit, eh?). Caleb can purchase fruits at most K times
(as he has only K gold coins in his pocket) to make the difference the minimum
possible.
Our brother is busy in celebrating his birthday to the fullest, and therefore, he
has handed this job to his best friend — you. Can you help him by finding the
minimum possible difference he can achieve between the number of Avacados
and Dragon fruits he owns?
Constraints:
1 ≤ n, m, k ≤ 100
Input Format:
The first line contains 3 space separated integers — N, M and K — denoting the
number of Avacados, number of Dragon fruits, and number of gold coins our
brother has.
Output Format:
Print the minimum possible difference between the number of Avacados and
Dragon fruits that Caleb can achieve.
#include <stdio.h>
int main() {
int t, n, m, k;
scanf("%d %d %d", &n, &m, &k);
while (k > 0) {
if (n > m) {
m++;
} else if (m > n) {
n++;
}
k--;
}
printf("%d\n", (n - m));
return 0;
}
7
Problem Description:
Given is an integer �. Simon chooses an integer 'a' from the positive integers
not greater than � with equal probability.
Constraints:
1 <= � <= 100
Input Format:
Input is given from Standard Input in the following format: N
Output Format:
Print the probability that 'a' is odd.
Explanation:
Assume N = 4 then
There are four positive integers not greater than 4: 1, 2, 3, and 4. Among them,
we have two odd numbers: 1 and 3. Thus, the answer is 2/4=0.5.
#include <stdio.h>
int main() {
int n;
float t;
scanf("%d", &n);
if (n % 2 == 0)
printf("%d", (n / 2) / n);
else {
t = (n / 2);
t = (t + 1) / n;
printf("%.9f", t);
}
return 0;
}
8
Laaysa with her friends going to the theatre for a movie. The seating
arrangement is triangular in shape. Theatre staff insisted the audience to sit in
odd row if the seat number is odd and in even row if the seat number is even.
But the instruction is very confusing for Laaysa and her friends.
So help them with the seating layout so that they can sit in correct seats.
Constraints:
4 ≤ N ≤ 20
Input Format:
Only line of input has single integer value representing the number of rows in
the theatre.
Output Format:
Print the layout based on the number of rows specified in input.
Instruction: To run your custom test cases strictly map your input and output
layout with the visible test cases.
#include <stdio.h>
int main() {
int t, i, j, c;
scanf("%d", &t);
for (i = 1; i <= t; i++) {
if (i % 2 == 0)
c = 2;
else
c = 1;
for (j = 1; j <= i; j++) {
printf("%d ", c);
c += 2;
}
printf("\n");
}
return 0;
}
9
Andy the die heart fan of AR Rahman went to the live concert that happened in
california with his family members.
The event management firm responsible for the event arranged the seats for the
audience in descending order of the maximum number of tickets booked for a
single family.
As per the seating arrangement family with the highest number of people
is allotted the seats in the front rows and the family with the lowest
number of people is allotted the seats in the last row.
For the convenience of the seating, arrangement volunteers to know how many
seats need to be positioned in each row the event management firm has
planned to develop the software which displays the exact seat layout if the total
number of rows is provided.
Can you help them with the logic of doing so?
Constraints:
1 ≤ no.of family members ≤ 20
Input Format:
The only line of input has a single integer representing the total number of
rows for the concert.
Output Format:
Print the seating arrangement layout based on the number of rows provided.
Refer sample test cases for format specification.
Instruction: To run your custom test cases strictly map your input and output
layout with the visible test cases.
#include <stdio.h>
int main() {
int nooffamilymembers, i, j;
scanf("%d", &nooffamilymembers);
for (i = nooffamilymembers; i >= 1; i--) {
for (j = 1; j <= i; j++) {
printf("%d ", i);
}
printf("\n");
}
return 0;
}