Monday, November 18, 2019

                                    E-BOX    

                                BASICS OF C PROGRAMMING   

Conditional Statements :-  Code Analysis

 PROBLEM -18

                                                    Luxury Bus Vs Share Auto


1st June 2014 is a very auspicious day and 3 of Sita's friends are getting married on that day. Sita has decided to purchase gifts for them in advance and she plans to visit 'The Personalized Gifts' store in Fun Mall. She is a regular visitor to this shop.

 

She has just read an article on sustainable enery resources and she was very much impressed by the article and she decided to follow some of the suggestions given in the article in order to contribute a small amount towards saving enery resources.

 

One of the suggestions in the article is Use Public Transport whenever possible. She decides to go by Luxury Bus or a Share Auto.
                OR              

The cost of travelling by Luxury Bux is Rs.X and the cost of travelling by Share Auto is Rs.Y.

 

She plans to spend minimal amount for travel.

Given X and Y, help her to decide whether to travel by luxury bus or by share auto.

 

Input and Output Format:

Input consist of 2 integers – X and Y. Assume that X is never equal to Y. Refer sample input and output for formatting specification.

 

[All text in bold corresponds to input and the rest corresponds to output]

Sample Input and Output 1:

Enter the cost of travel by luxury bus

40

Enter the cost of travel by share auto

35

Minimal cost travel is by auto

 

Sample Input and Output 2:

Enter the cost of travel by luxury bus

30

Enter the cost of travel by share auto

45

Minimal cost travel is by bus


SOLUTION :




Saturday, November 16, 2019

                                   E-BOX    

                               BASICS OF C PROGRAMMING   

Conditional Statements :-  Code Analysis

 PROBLEM -17

                                                                    LIFT I

 

The Personalized Gifts store is in the nth floor.


Sita gets into a lift in the ground floor.



The lift that Sita gets in does not stop in all floors. It stops in only 3 floors numbered n1, n2 and n3.

She wants to get down in the floor that is closest to n. If there are 2 choices, she always prefers to climb down the stairs rather than climbing up.

Help Sita in deciding the floor she should get down from the lift.

 

Input and Output Format:

Input consists of 4 integers corresponding to n, n1, n2 and n3.  [n1<n2<n3]

Output consists of an integer that corresponds to the floor number where she would get down.

 

Sample Input 1:

10

4

8

15

 

Sample Output 1:

8

 

Sample Input 2:

10

4

8

12

 

Sample Output 2:

12



SOLUTION:


Your Submission is correct.

1#include
2#include
3int main()
4{
5  int n,n1,n2,n3,a,b,c;
6  scanf("%d",&n);
7  scanf("%d",&n1);
8  scanf("%d",&n2);
9  scanf("%d",&n3);
10  a=abs(n-n1);
11  b=abs(n-n2);
12  c=abs(n-n3);
13  if((a!=b) && (a!=c) && (b!=c))
14  {
15  if((a
16    printf("\n%d",n1);
17  else if(b
18    printf("\n%d",n2);
19    else
20      printf("\n%d",n3);
21    }
22  else if((n1==n) || (n2==n) || (n3==n))
23    printf("\n%d",n);
24   else
25   {
26     if(a==b)
27     {
28       if(n1>n)
29         printf("\n%d",n1);
30       else
31         printf("\n%d",n2);
32     }
33     else if(a==c)
34     {
35       if(n1>n)
36         printf("\n%d",n1);
37       else
38         printf("\n%d",n3);
39     }
40     else
41     {
42       if(n2>n)
43         printf("\n%d",n2);
44       else
45         printf("\n%d",n3);
46     }
47   }
48return 0;
49}

                                   E-BOX    

                             BASICS OF C PROGRAMMING   

Conditional Statements :-  Code Analysis

 PROBLEM -16:

                                               LAB SEATING ARRANGEMENT

 There are 2 programming labs, each with a seating capacity of 90. There are 240 students with registration numbers from 1 to 240. All 240 students cannot be accomodated in the labs at the same time. It has been decided to conduct theory classes for 60 students every week. It has been planned to conduct theory classes for all students with registration numbers being a multiple of 4. Students with registration numbers from 1 to 120 with registration numbers not a multiple of 4 need to be seated in Programming Lab I and students with registration numbers from 121 to 240 with registration numbers not a multiple of 4 need to be seated in Programming Lab II.

Given the registration number of a student, write a  program to specify the lab or hall in which the student needs to be seated.

 

Input Format:

Input consists of 1 integer which corresponds to the registration number of the student.

 

Output Format:

Output consists of the string “Lab 1” or “Lab 2” or “Theory Session”.

Refer sample input and output for further formatting specifications.

 

Sample Input and Output:

[All text in bold corresponds to input and the rest corresponds to output]

 

Enter the registration number of the student

3

Lab 1


SOLUTION :




Friday, November 15, 2019

                                                                   E-BOX    

                            BASICS OF C PROGRAMMING   

Conditional Statements :-  Code Analysis

 PROBLEM -15:

                                     CHARACTER – UPPER OR LOWER

Write a  program that accepts a character as input and checks whether it is an uppercase letter or lowercase letter or neither.

 

Input Format:

Input consists of a single character.

Output Format:

Output consists of a single line. Refer sample output for the format.

 

Sample Input 1 :

c

Sample Output 1 :

c is lowercase letter

 

Sample Input 2:

A

Sample Output 2:

A is uppercase letter

 

Sample Input 3:

5

Sample Output 2:

5 is neither an uppercase or lowercase letter




SOLUTION :




Thursday, November 14, 2019

                                  E-BOX    

                             BASICS OF C PROGRAMMING   

Conditional Statements :-  Code Analysis

 PROBLEM - 14
                                                             

                                                           CALCULATE GRADE

 Write a program that accepts the marks in 3 subjects of a student , calculates the average mark of the student and prints the student's grade. If the average mark is greater than or equal to 90, then the grade is 'A'. If the average mark is 80 and between 80 and 90, then the grade is 'B'. If the average mark is  70 and between 70 and 80, then the grade is 'C'. If the average mark is  60 and between 60 and 70, then the grade is 'D'. If the average mark is 50 and between 50 and 60, then the grade is 'E'. If the average mark is less than 50, then the grade is 'F'.

 

Input Format:

Input consists of 3 lines. Each line consists of an integer.

Output Format:

Output consists of a single line. Refer sample output for the format.

 

Sample Input 1 :

45

45

45

Sample Output 1 :

The grade is F


Sample Input 2:

91

95

100

Sample Output 2:

The grade is A




SOLUTION :


 


Sunday, November 10, 2019

                                     E-BOX    

                               BASICS OF C PROGRAMMING   


Conditional Statements :-  Code Analysis

 PROBLEM -10:

                                                                LIFT I

 

The Personalized Gifts store is in the nth floor.


Sita gets into a lift in the ground floor.



The lift that Sita gets in does not stop in all floors. It stops in only 3 floors numbered n1, n2 and n3.

She wants to get down in the floor that is closest to n. If there are 2 choices, she always prefers to climb down the stairs rather than climbing up.

Help Sita in deciding the floor she should get down from the lift.

 

Input and Output Format:

Input consists of 4 integers corresponding to n, n1, n2 and n3.  [n1<n2<n3]

Output consists of an integer that corresponds to the floor number where she would get down.

 

Sample Input 1:

10

4

8

15

Sample Output 1:

8

 

Sample Input 2:

10

4

8

12

Sample Output 2:

12



SOLUTION :


INPUT 1   INPUT 2    INPUT 3   INPUT 4  INPUT 5   INPUT 6   INPUT 7

20             20              50             30            40            25             12

19             12              40             17            24            19             10

22             19              45             32            39            22             14

27             27              49             25            41            26             33












                                                 E-BOX                                                     BASICS OF C PROGRAMMING       i -...

https://amzn.to/2LAmadv