Sunday 26 February 2017

IO 8

QUESTION DESCRIPTION :


Write a program to find the largest of three numbers using ternary operator

Input and Output Format:

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output.


TEST CASE 1


INPUT

4 5 6

OUTPUT

The biggest number is:6


TEST CASE 2


INPUT

99 9999 99999

OUTPUT

The biggest number is:99999


EXPLANATION : 

The code requires you to print the largest among the 3 numbers but you need to use the ternary operator ( Ternary Operation )

ALGORITHM : 

  • Accept the numbers from the user ( a,b,c )
  • Check the largest number using ternary operator
  • Print the largest number with the appropriate message

SOLUTION : (Please use this as reference only)

CODE


Wednesday 22 February 2017

PRINT 2

QUESTION DESCRIPTION :

Write a C program to print all numbers between a and b ( a and b inclusive) using a while loop.

Input format:

Input consists of 2 integers. The first integer corresponds to a and the second integer corresponds to b . Assume a>=b.

Output format:

Refer sample input and output for formatting specifications.


TEST CASE 1

INPUT

10
4

OUTPUT

10
9
8
7
6
5
4


TEST CASE 2


INPUT

5
4

OUTPUT

5
4


EXPLANATION :
According to this program we need enter two integer value and we have print a series of numbers with the help of simple while looping statement. ( While loop )


ALGORITHM : 

  • Input the two numbers from the user ( a,b )
  • Run a while loop with the condition a>b ( while (a>b) )
  • Print the value of "a" variable 
  • Reduce the value of a by 1 ( a-- )
SOLUTION : (Please use this as reference only)

CODE

Lab seating Arrangement

QUESTION DESCRIPTION :

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 accommodated in the labs at the same time. It has been decided to conduct theory class for 60 students every week. It has been planned to conduct theory classes for all students with register number being a multiple of 4. Students with registration number from to 1 to 120 with registration number not a multiple of 4 need to be seated in programming lab1 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 student, write a C program to specify the lab or hall in which student need to be seated.

Input Format:

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

Output format:

Output consists of string "Lab 1" or "Lab 2" or "Theory session " or ?Incorrect Register Number?

Refer sample input and output for further formatting specifications.


TEST CASE 1
 
INPUT
16
OUTPUT

Theory session

TEST CASE 2

INPUT
239
OUTPUT

Lab 2


EXPLANATION :

The code requires you to input a number and output the class room of the person , i.e. either Theory session or Lab 1 or Lab 2 .

The input will be an integer corresponding to the Registration Number of the student.

The output is the session that the person has to attend.


ALGORITHM : 

  • Accept the number from the user ( a )
  • Check if the person has to attend theory session ( a%4==0&&a!=0 ) 
  • Print Theory session if the case is true .
  • If it is false , check for Lab 1 ( a<120&&a>=1 )
  • Print Lab 1 if the case is true
  • If it is false , check for Lab 2 ( a<240&&a>120 )
  • Print Lab 1 if the case is true
  • If all other cases are false check for wrong register number ( a>240||a<1 )
  • Print Incorrect Register Number if the case is true
SOLUTION : (Please use this as reference only)
CODE

In/out

QUESTION DESCRIPTION :

Ms.Kirthiga, the faculty handling programming lab for you is very strict. Your seniors have told you that she will not allow you to enter the weeks lab if you have not completed atleast half the number of problems given last week. Many of you didnt understand this statement and so they requested the good programmers from your batch to write a c program to find whether a student will be allowed into a week lab given the number of problems given last week and the number of problem solved by the students in that week.

Input format:
Input consists of 2 integers. The First integer corresponds to the number of problems given and the second integer corresponds to the number of problems solved.

Output format:
Output consists of the string "IN" or "OUT"
Refer sample input and output for further formatting specifications.


TEST CASE 1

INPUT

8
3

OUTPUT

OUT


EXPLANATION :

The code requires you to check weather a person is eligible to enter the LAB or not.

The entry criteria is that a person should have completed at least 50% or half of the problems given to them last week.

The input consists of 2 numbers , first one is the number of problems given to the person last week and second is the number of problems done by him/her.

Check if the person has done 1/2 or more problems and print IN or OUT according to the condition.

ALGORITHM : 

  • Input two integers from the user ( a,b )
  • Check if questions done is more than 1/2 of the questions given (  b>=(int)(a/2) )
  • If the condition is true ,print IN
  • Otherwise print OUT

SOLUTION : (Please use this as reference only)
CODE
 

A Task

QUESTION DESCRIPTION :

A task is given to 3 persons to complete it within a particular time. If the person exceeds the time limit he will be disqualified . Only those who complete it within the given time limit is qualified. Among the qualified persons. the person who complete the task first will be rewarded.Write a C program to find the person who is rewarded.

Input Format:

First Input corresponds to the time limit for the task in hours . Second, third and fourth input corresponds to the number of hours taken by the first, second and third persons respectively to complete the task.

Output format:

Display the person who completes first.


TEST CASE 1
 
INPUT

10 5 4 7

OUTPUT

Second person wins!!


TEST CASE 2

INPUT

4 9 6 7

OUTPUT

No person wins!!


EXPLANATION :

The code requires you check for the time taken by 3 people to complete a task and find out who won the competition by comparing the time taken by them ( the person with the least time wins ) . But if the best time is > than the disqualification time , then all the 3 people are disqualified .

The input format is 4 integers representing the time limit and the time taken by the 3 people to complete the tasks.


ALGORITHM :

  • Input 4 integers from the user ( r , a , b , c )
  • Check weather first person has won ( r>a&&a<b&&a<c )
  • Check weather second person has won ( r>b&&b<a&&b<c )
  • Check weather third person has won ( r>c&&c<a&&c<b )
  • According to the winner , print the correct output
  • If no one wins ( all conditions fail ) , print No person wins!!
# Note :  r is the max time alloted , a,b,c are the values of the time taken by person 1,2,3 respectively
SOLUTION : (Please use this as reference only)
CODE
 

Class Representative

QUESTION DESCRIPTION :

A student is eligible to be a class representative if his or her attendance % and marks is greater that 90% and he or she doesnt have any arrears. Given the attendance % ,mark % and number of arrears, write a C program to determine whether a student is eligible to be a Class Representative or not.

Input format:
Input consists of 2 float and an integer. The first float corresponds to the attendance % and the second float corresponds to the percentage of marks. The third input is an integer which corresponds to the number of arrears.

Output format :
Output consists of the string "Eligible " or "Not Eligible"
Refer sample input and output for further formatting specifications.


TEST CASE 1

INPUT

90.1
90.1
0 

OUTPUT

Eligible
 

TEST CASE 2

INPUT

90.0
90.0
0

OUTPUT

Not Eligible


EXPLANATION :

The code requires you to accept 2 float inputs corresponding to attendance % , marks % and  an integer corresponding to the number of arrears he/she has in exams.

The result will be Eligible or Not Eligible , depending on the conditions mentioned above ( attendance and exam % >90 and arrears=0  , then the person is eligible ) 


ALGORITHM :

  • Accept 3 numbers from the user , first two are float and the last one is integer ( a,m,ar )
  • Check for eligibility for being the Class representative ( (a>90.0)&&(m>90.0)&&ar==0 )
  • If the above test case is true , print Eligible
  • If the above test case is not true , print Not Eligible
#Caution : Person with 90.0 % is not eligible , %age should be grater than 90.0
 
SOLUTION : (Please use this as reference only)
 
CODE
 

Tuesday 21 February 2017

Splitting into Teams

QUESTION DESCRIPTION :

During the Physical Education hour, PT sir has decided to conduct some team games. He wants to split the students in the class into equal sized teams. In some cases, there may be some students who are left out from teams and he wanted to use the left out students to assist him in conducting the team games.
For instance, if there are 50 students in the class and if the class has to be divided into 7 equal sized teams, 7 students will be there in each team and 1 student will be left out.
PT sir asks your help to automate this team splitting task. Can you please help him out?

Input Format:
Input consists of 2 integers. The first integer corresponds to the number of students in the class and the second integer corresponds to the number of teams.


TEST CASE 1

INPUT

60
8

OUTPUT

The number of students in each team is 7 and left out is 4


TEST CASE 2

INPUT

100
22

OUTPUT

The number of students in each team is 4 and left out is 12


EXPLANATION :

The code is a basic mathematics problem which uses the divide and modulo operation , to calculate the number of people in each group and the number of people left out after equal division in groups.

For counting the number of people in each group , we use the / operation and for the people left out we use the % operation
 
The input format is two integers , first one is the number of students in total and the second one is the number of teams to be formed


ALGORITHM : 

  • Take two inputs from the user , for number of students and teams ( a,b )
  • Calculate the number of people in each team ( a/b )
  • Calculate the number of people left out ( a%b )
  • Print the result with appropriate message
 
SOLUTION : (Please use this as reference only)

CODE

Calculating Gain Percentage

QUESTION DESCRIPTION :

Vikram buys an old scooter for Rs. A and spends Rs. B on its repairs. If he sells the scooter for Rs. C , what is his gain %?
Write a C program to compute the gain %.
Input Format:
The first input is an integer which corresponds to A. The second input is an integer which corresponds to B. The third input is a float which corresponds to selling price



TEST CASE 1

INPUT

4700
800
5800

OUTPUT

The gain percentage is=5.45


EXPLANATION :

The code requires you to accept 3 integers from the user , which correspond to Cost Price , Repair Price and Selling Price respectively and then find the gain/profit percentage for the given input.

FORMULA :

Gain % = (( Selling Price - ( Cost Price + Repair Cost )) / (Cost Price + Repair Cost ) )*100


ALGORITHM : 

  • Accept 3 integers from the user ( a,b,c )
  • Calculate the gain % by using the given formula ( ((c-a-b)*1.0/(a+b))*100 ) ( Multiplying by 1.0 converts it to float ( can be used instead of type casting ) )
  • Print the result with the required message

SOLUTION : (Please use this as reference only)

CODE

Finding bitwise AND of two numbers

QUESTION DESCRIPTION :

Write a program to find the bitwise AND of two decimal numbers.
An AND gate reads 2 input either 0 or 1 and outputs 1 iff both the inputs are 1. Similarly write a program to read two decimal numbers and finds AND of two numbers.
EXAMPLE :
(3)10 = (011)2
(5)10 = (101)2
AND of 3 and 4 is :
(1)10 = (001)2
TEST CASE 1

INPUT

12 23

OUTPUT

Bitwise AND of 12 and 23 is:4


EXPLANATION :

The code requires you to accept two inputs from the user and perform the AND & operation ( Bitwise Operators ) on them and print the result.


ALGORITHM : 

  • Input two integers from the user ( a,b )
  • Calculate the bitwise AND ( a&b )
  • Print the result with the required messages. 

SOLUTION : (Please use this as reference only)
CODE

Finding OR of two numbers

QUESTION DESCRIPTION :

Write a program to find the bitwise OR of two decimal numbers.
An OR gate reads 2 input either 0 or 1 and outputs 0 iff both the inputs are 0 else 1. Similarly write a program to read two decimal numbers and finds OR of two numbers.

EXAMPLE :
(3) 10 = (011) 2
(5) 10 = (101) 2
OR of 3 and 4 is :
(7) 10 = (111) 2


TEST CASE 1

INPUT

12
23

OUTPUT

Bitwise OR of 12 and 23 is=31


EXPLANATION :

The code requires you to accept two inputs from the user and perform the OR | operation ( Bitwise Operators ) on them and print the result


ALGORITHM : 

  • Input two integers from the user ( a,b )
  • Calculate the bitwise OR ( a|b )
  • Print the result with the required messages. 

SOLUTION : (Please use this as reference only)

CODE

FOUR SEASONERS

QUESTION DESCRIPTION :

Dinesh also joined the group of 3 idiots and now their group is called Four Seasoners. Meanwhile, Binoy has moved to a new house in the same locality. Now the houses of Ajay, Binoy and Chandru are in the located in the shape of a triangle. Dinesh also has moved to a house in the same locality. When Ajay asked Dinesh about the location of his house , Dinesh said that his house is equidistant from the houses of the other 3. Though Ajay was good in Mathematics, he was puzzled. Can you please help Ajay out?

Given the 3 vertices {(x1,y1), (x2,y2) and (x3,y3)} of a triangle, write a C program to determine the point which is equidistant from all the 3 vertices.

Input Format:
Input consists of 6 integers. The first integer corresponds to x1 . The second integer corresponds to y1. The third and fourth integers correspond to x2 and y2 respectively.
The fifth and sixth integers correspond to x3 and y3 respectively.


TEST CASE 1

INPUT

2 4
10 15
5 8

OUTPUT

Dinesh house is located at (5.7,9.0)


EXPLANATION :

The code requires you to take input , 3 set of coordinates ( x,y ) , for three friends of Dinesh and calculate the coordinates of his house such that is it at equal distance form all the three houses.
If we consider the 3 houses to be the three vertices of the triangle , then the point at equal distance of  all of them is the circumcentre Circumcenter ). So we have to calculate the circumcenter of the triangle , whose coordinates have been given.


QUESTION ISSUES :

The circumcenter of the triangle in the given example ( sample I/O ) is ( -230.5 , 181.5 ) , but the output given,  corresponds to the centroid of the given triangle. So either the input or output needs to be changed or the question description. For the sake of getting the correct output , I will calculate the centroid instead of the circumcenter. ( The triangle should be an equilateral triangle for circumcenter and centroid to coincide ( no such condition is given ) )


ALGORITHM :

  • Take 6 inputs from the user corresponding to the x,y coordinates of the three houses ( x1,y1,x2,y2,x3,y3 )
  • Calculate the centroid of the triangle ( (x1+x2+x3)/3.0 , (y1+y2+y3)/3.0 )
  • Print the result with the required message.
 
 SOLUTION : (Please use this as reference only)

CODE

Grade The Steel

QUESTION DESCRIPTION : 

A certain grade of steel is graded according to the following conditions.

Hardness must be greater than 50.
Carbon content must be less than 0.7.
Tensile strength must be greater than 5600.
The grades are as follows:

Grade is 10 if all three conditions are met.

Grade is 9 if conditions (i) and (ii) are met.
Grade is 8 if conditions (ii) and (iii) are met.
Grade is 7 if conditions (i) and (iii) are met.
Grade is 6 if only one condition is met.
Grade is 5 if none of three conditions are met.
Write a program, if the user gives values of hardness, carbon content and tensile strength of the steel under consideration and display the grade of the steel. 


TEST CASE 1

INPUT

2
53 0.7 5602
55 0 5499

OUTPUT

Grade 10
Grade 9


EXPLANATION :

The code is a basic decision making question , requiring to use if and else ifControl Statements ). The first input is the number of test cases that the user will input. Then there will be a set of three inputs referring to the values hardness, carbon content  and tensile strength respectively. We have to check the values under different conditions and rate the steel under different grades from 1 to 10 .


ALGORITHM :

  • Input the number of test cases from the user ( t )
  • Run loop from 0 to the number of test cases ( i<t )
  • Input the values of hardness, carbon content and tensile strength ( hs,cc,ts )
  • Check for grade 10 ( hs>=50&&cc<=0.700000000&&ts>=5600 )
  • Check for grade 9 ( hs>=50&&cc<=0.7 )
  • Check for grade 8 ( cc<=0.7&&ts>=5600 )
  • Check for grade 7 ( hs>=50&&ts>=5600 )
  • Check for grade 6 ( hs>=50||cc<=0.7||ts>=5600 )
  • If all the conditions are false then it is grade 5
  • Print the grade with required message
  • Redo this for all other test cases 

SOLUTION : (Please use this as reference only)

CODE


 

PLACING THE FLAG POST

QUESTION DESCRIPTION :

The shape of the college ground is Square. For the Independence day Flag Hoisting Function, it has been decided to place the flag post at the exact center of the ground. Can you please help them in placing the flag post at the exact center?
Given the coordinates of the left bottom vertex of the square ground and the length of the side, you need to write a program to determine the coordinates of the centre of the ground.
[Assumption --- Length of the side is always even]
Input Format:
Input consists of 3 integers. The first integer corresponds to the x-coordinate of the left bottom vertex. The second integer corresponds to the y-coordinate of the left bottom vertex. The third integer corresponds to the length of the square.


TEST CASE 1

INPUT

4 0 8

OUTPUT

centre of the ground is at(8,4)


EXPLANATION :

This question requires you to find the center of the square whose left bottom coordinates ( x,y ) and length is given. To find the coordinates we use basic geometry.

FORMULA :

Center X : x + l/2 , Center  Y : y +l/2


ALGORITHM :


  • Input the lower bottom x and y coordinates ( x,y )
  • Input the length of square side ( l )
  • Calculate the coordinates using the formula and print it with appropriate message ( print as int %d , "center" as used by me is from American English ) 

SOLUTION : (Please use this as reference only)

CODE

Find Remainder

QUESTION DESCRIPTION :


Write a program to find the remainder when two given numbers are divided.

Input

The first line contains an integer T, total number of test cases. Then follow T lines, each line contains two Integers A and B.

Output

Find remainder when A is divided by B.

Constraints

1 ? T ? 1000
1 ? A,B ? 10000


TEST CASE 1

INPUT

3
1 2
100 200
10 40

OUTPUT

Remainder is 1
Remainder is 100
Remainder is 10


EXPLANATION :

This problem is similar to Modulo Operations , but you have to do it for multiple inputs , the number of inputs is given by the first integer received from the user.


QUESTION ISSUES :

The constraints given contain " ? " but it should be either " < " or " <= "


ALGORITHM:

  • Input the number of test cases from the user ( t )
  • Run a loop till t , to get all input cases
  • Input the two numbers from the user ( a,b )
  • Compute the remainder using modulo operator ( a%b )
  • Print the result
  • Redo this for all other test cases 

SOLUTION : (Please use this as reference only)

CODE

Greedy puppy

QUESTION DESCRIPTION :

Tuzik is a little dog. But despite the fact he is still a puppy he already knows about the pretty things that coins are. He knows that for every coin he can get very tasty bone from his master. He believes that some day he will find a treasure and have loads of bones.

And finally he found something interesting. A wooden chest containing N coins! But as you should remember, Tuzik is just a little dog, and so he cant open it by himself. Actually, the only thing he can really do is barking. He can use his barking to attract nearby people and seek their help. He can set the loudness of his barking very precisely, and therefore you can assume that he can choose to call any number of people, from a minimum of 1, to a maximum of K.

When people come and open the chest they divide all the coins between them in such a way that everyone will get the same amount of coins and this amount is maximal possible. If some coins are not used they will leave it on the ground and Tuzik will take them after they go away. Since Tuzik is clearly not a fool, he understands that his profit depends on the number of people he will call. While Tuzik works on his barking, you have to find the maximum possible number of coins he can get.

Input
The first line of the input contains an integer T denoting the number of test cases. Each of next T lines contains 2 space-separated integers: N and K, for this test case.

Output
For each test case output one integer - the maximum possible number of coins Tuzik can get.

Constraints
1<=T<=50
1<=N, K<=105
In the first example he should call two people. Each of them will take 2 coins and they will leave 1 coin for Tuzik.

In the second example he should call 3 people


TEST CASE 1


INPUT

2
5 2
11 3

OUTPUT

1
2


EXPLANATION :

As the size of the inputs in the problem is very small ( in the order of 10^2 ) , we can simply use brute-forcing ( Brute Forcing ) and test every possible case and print the value of the maximum coins that the dog gets.

As the dog only gets what remains after equal spitting , this can be calculated by using the modulo " % "Modulo ) operation .

Example :

For 2'nd test case :  ( 11,3 ) :
  • He can call maximum of 3 people
  • If he calls only 1 person , the person will take all the coins , leaving him with nothing
  • If he calls 2 people , he will be left with only 1 coin , as the two people take 5 , 5 coins each.
  • If he calls 3 people , each one will take 3 coins , leaving him with 2 coins
  • So the best case for him is to call 3 people so he can get 2 coins.
The input format is :
  • An integer , to represent the number of test cases ( number of times the user will provide distinct values of N and K)
  • Pair of integers representing N and K values respectively ( this will be the input format for next t cases )
The result will be biggest modulo value that a number gives with N , such that the number is less than K.


ALGORITHM: 

  • Input an integer from the user, representing the number of test cases ( t )
  • Run a loop till the number ( for/while loop )
  • Accept two integers from the user ( n,k )
  • Take a variable "max" , to store the max coins the dog can get ( max=0 )
  • Run a loop from 1 till K ( for(j=1;j<=k;j++) )
  • Check the amount of coins left to him if he calls j number of people ( n%j )
  • If the value of coins left is more than previous max , replace it with previous max ( max=n%j )
  • After the loop exits , print the maximum value , with the required message ( max )
  • Change max back to 0 
  • Redo this for all the N,K values

SOLUTION : (Please use this as reference only)

CODE

Modulo of numbers(Integer data type)

QUESTION DESCRIPTION :

Jenny's home work for Fifth day is to find modulo of two numbers, help jenny to solve the problem.


TEST CASE 1
 
INPUT

6
2

OUTPUT

The reminder of two number is:0


EXPLANATION:

The code requires you to perform modulo "%"Modulo Operation ) operation on the two integers received from the user. 


ALGORITHM:  

  • Take two variables from the user ( a,b )
  • Calculate the modulo ( a%b )
  • Print it with the exact required message ( Spelling of remainder is wrong )

SOLUTION : (Please use this as reference only)

CODE

Size of Data Types

QUESTION DESCRIPTION :

Write a program to produce correct size of various data types on your computer


TEST CASE 1

INPUT

0

OUTPUT

Size of char:1
Size of int:4
Size of short int:2
Size of long int:8
Size of float:4
Size of double:8


EXPLANATION :

The problem requires you to print the exact size of the different data-types used in C. There are two methods of doing this , either print the size directly or use the sizeof() The sizeof() function ) function to print the exact size of the variable given in arguments.

ALGORITHM :

  • To directly print the exact size just use the print statement and put whatever is required to it.
Using the sizeof() operator :
  • Declare a variable of each type ( char , int , short , long , float , double
  • Use the sizeof() to get the size of each datatype ( sizeof( variable ) )
  • Print the long unsigned integer value Different Datatypes in C ) received from the sizeof() function with the exact output message ( %ld )

SOLUTION : (Please use this as reference only)

CODE (Direct Print)

CODE (Size Of)

Differenzia

QUESTION DESCRIPTION :

In a country named Differenzia the minors and senior citizens are not eligible to vote. Only people aged between 18 to 60 (both inclusive) are eligible to vote. Write a program to determine a person in Differenzia is eligible to vote.


TEST CASE 1 

INPUT

18

OUTPUT

Eligible


TEST CASE 2

INPUT

2

OUTPUT

Not Eligible


EXPLANATION :

The problem is a basic if else if else statements ) problem , that requires you to check weather the person who is going to vote is eligible to vote or not. The input is the age of a person and you have to check weather the age is between 18-60 , if yes , the person is eligible , else he is not.


ALGORITHM :

  • Take input from the user ( a )
  • Check the input satisfies the eligibility criteria or not ( a>=18 && a<=60 )
  • If yes , print Eligible
  • Otherwise print Not Eligible 
SOLUTION : (Please use this as reference only)

CODE





Number of digits

QUESTION DESCRIPTION :

C Program to Count number of digits in number without using mod operator


TEST CASE 1

INPUT

1234

OUTPUT

Number of Digits:4


TEST CASE 2

INPUT

874527

OUTPUT

Number of Digits:6


EXPLANATION :

The problem requires you to count the number of digits in a number being input. The method used is to continuously divide the number by 10 , to reduce the digits by 1 and increase the counter


ALGORITHM :

  • Take input from the user ( a )
  • Take a while loop , with the condition , number > 0 ( a>0 )
  • Divide the number by 10 and save it in the original variable ( a=a/10
  • Increase the count by 1 ( i++ )
  • Loop till the number becomes 0 ( loop condition is not satisfied )
  • Print the counter ( i )
SOLUTION : (Please use this as reference only)

CODE

Addition of numbers(Integer data type)

QUESTION DESCRIPTION :

Jennys home work for first day is to find addition of two numbers, help jenny to solve the problem.


TEST CASE 1 

INPUT

6
2

OUTPUT

The addition of two number is:8


EXPLANATION :

This is a simple problem which requires you to accept two numbers and then print addition of the first number and the second number.


ALGORITHM :

  • Take input from the user ( a,b )
  • Add the two numbers ( a+b ) 
  • Print the result.

SOLUTION : (Please use this as reference only)

CODE

Multiplication of numbers(Integer data type)

QUESTION DESCRIPTION :

Jennys home work for Third day is to find Multiplication of two numbers, help jenny to solve the problem.

TEST CASE 1 

INPUT

6
2

OUTPUT

The Multiplication of two number is:12


EXPLANATION :

This is a simple problem which requires you to accept two numbers and then print the multiplication of the first and the second number.

ALGORITHM :

  • Take input from the user ( a,b )
  • Multiply the two numbers and print the result.( a*b )

SOLUTION : (Please use this as reference only)

CODE



Float Division of numbers

QUESTION DESCRIPTION :

Harinis home work for fourth day is to divide two numbers, help Harini to solve the problem.


TEST CASE 1 

INPUT

7.2 3.4

OUTPUT

The Division of two number is:2.117647


EXPLANATION :

This is a simple problem which requires you to accept two numbers and then print the division of the first number by the second number. ( ImpDividing Two Integers Gives Integers )


ALGORITHM :
  • Take input from the user ( a,b )
  • As dividing two integers gives you an integer , you either need to parse ( Parsing ) it to float or take the input as float ( I took the input as float )
  • Divide the two numbers and print the result.( a/b )
SOLUTION : (Please use this as reference only)


CODE


Swap Numbers

QUESTION DESCRIPTION :

Write a C Program to swap two variables without using third or temp variable


TEST CASE 1 

INPUT

20
5

OUTPUT

Values after Swapping
value of a is:5
value of b is:20


EXPLANATION : 

The code requires you to receive an input of two numbers , swap them and display the results ( Different Swapping Methods ). I have used the mathematical approach.


ALGORITHM :

  • Take two inputs from the user ( a,b )
  • Add second value to the first value and store it in the first variable ( a=a+b )
  • To add new value to second variable , subtract the value of second variable from the value of the first variable and store it in the second one ( b=a-b )
  • Perform a similar operation on the first variable ( a=a-b )
  • The numbers are swapped , print them with the required output message.

SOLUTION : (Please use this as reference only)

CODE


IO 35

QUESTION DESCRIPTION :


Write a program to display a grocery bill of the product purchased in the small market by John by getting following input from the user

Get the product name
Get the price of the product(Price per Unit)
Get the quantity of the product purchased
Input and Output Format:

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output.


TEST CASE 1

INPUT

soap
33.00
2

OUTPUT

Product Details
soap
33.000000
2
Bill:66.00

EXPLANATION : 

The code requires you to receive an input of Product Name , Product Price and the Quantity of the product bought and then print the Billing Details. ( Strings )

ALGORITHM :

  • Take a string as a char array to receive the name of the product ( ch[500] )
  • Take two float variables and an integer variable to store bill amount, price of individual product and number of such products bought ( p , f  , u )
  • Receive the inputs for the respective categories from the user ( %s , %f , %d )
  • Multiply the individual product price with the number of products bought and store it in the bill amount ( p=u*f  )
  • Print the result according to the required format.

SOLUTION : (Please use this as reference only)

CODE


IO 9

QUESTION DESCRIPTION :

Let us help Raje to perform basic bitwise operation by providing three inputs given to the program with the following conditions are met,

Bitwise And
Bitwise OR
Bit Wise Not

Input and Output Format:

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output.


TEST CASE 1

INPUT

23 4

OUTPUT

Bitwise And of 23 and 4=4
Bitwise OR of 23 and 4=23
Bit Wise Not of 23 and 4=19


EXPLANATION:

The code requires you to print the AND( & ), OR ( | ) , NOT( ~ ) values of the given integer inputs. ( BITWISE OPERATIONS ). The input will be two integers , on which you have to perform BITWISE operations. ( How do BITWISE operators work ) 

ALGORITHM :


  • Accept the two numbers ( a,b )
  • Calculate AND of the two numbers ( a&b )
  • Calculate OR of the two numbers ( a|b )
  • Calculate XOR of the two numbers ( a^b )

QUESTION ISSUES :

The last operation " NOT " , requires only 1 input ( ~ works with only one input ). The result of the NOT case is the XOR value of the 2 inputs ( a^b ) 


SOLUTION : (Please use this as reference only)

CODE






IO 5

QUESTION DESCRIPTION :

Write a program to scan the given input and perform unary prefix increment and decrement operators. Condition : Variable name to be used: Preadd, Presub, Posadd, Possub


TEST CASE 1 

INPUT

2

OUTPUT

The Value of num=2
The Value of num++=2
The new Value of num=3
The Value of num=3
The Value of num--=3
The new Value of num=2


TEST CASE 2

INPUT

7

OUTPUT

The Value of num=7
The Value of num++=7
The new Value of num=8
The Value of num=8
The Value of num--=8
The new Value of num=7


EXPLANATION :

The code requires you to input a number and print the print the post-increment , post-decrement values of the input received from the user ( Increment and Decrement Operators ).


QUESTION ISSUES :

The question asks us to perform the " unary prefix increment and decrement " on the given user input , but the sample input output requires us to do unary postfix increment and decrement. Similarly, the variables Posadd and Possub are not required.

 
ALGORITHM :


  • Take an input form the user , print it. ( inp )
  • Post increment the value of the number and print it. ( inp++ )
  • Print the number again ( inp )
  • Print the number again ( inp )
  • Post decrement the number and print it. ( inp-- )
  • Print the value of the number again ( inp )
#Remember : Print the output with the correct output message , with the correct case.


SOLUTION : (Please use this as reference only)

CODE



Monday 20 February 2017

Equation

QUESTION DESCRIPTION :

Given N,A,B,C, find how many solutions exist to the equation : a + b + c <= N, such that 0 <=a <=A, 0 <= b <= B, 0<= c <= C.

Input

The first line contains the number of test cases T. Each test case contains 4 integers, N,A,B,C. 0 <= N,A,B,C <= 2500

Output

Output T lines, one for each test case.


TEST CASE 1

INPUT

2
4 3 2 1
1 1 1 1 

OUTPUT

20
4


EXPLANATION :

The program requires you to take 5 integers as input from the user . The first number is the number of time the user wants you to run your code ( number of test cases ). The second number is N , the third one is A , fourth one is B , fifth one is C.
The algorithm used is brute forcing ( Brute Forcing, using a quadruple nested loop ( Nested Loops ) , with 3 for loops used for the core algorithm.

To do the question we take all values of a,b,c which satisfy a<=A , b<=B , c<=C and check weather they satisfy a+b+c<=N , if that is true we increase the value of the counter by 1 ( i ) . Then finally after testing all cases the result is printed. Then before going to the next test case , we decrease number of test cases ( t--  ) by 1 and reset counter to 0 ( i=0 )


ALGORITHM :
  • Take an integer input which signifies the number of test cases ( t )
  • Run a loop from 0 till < t or from t till t > 0
  • Input the first test case values ( N,A,B,C )
  • Run 3 nested loops , first till A , second till B , third till C
  • In the third loop test for the valid case ( a+b+c<=N )
  • If the case is true , increase counter by 1 ( i++ )
  • After the loops end print the counter ( printf("%d",i); )
  • Reset the counter to 0 and decrease the test case by 1 ( i=0 , t-- )
  • Rerun the loops again for the new values , till t is 0
  • Return and exit


SOLUTION : (Please use this as reference only)


CODE

IO 28

QUESTION DESCRIPTION :


Write a program to print the sum of even numbers between 1 and 200

Input and Output Format:

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output.


TEST CASE 1


INPUT

0

OUTPUT

10100


EXPLANATION :

The program requires you to print the sum of first 200 numbers starting from 1. That can either be done using a simple for or while loop ( For Loop Concepts , While Loop Concepts)


ALGORITHM :

  • Take a loop from 0 to 200.
  • Take a variable ( sum ) and add loop variable ( i ) to it , to calculate the sum.
  • Increase the loop variable by 2 instead of 1 ( i=i+2 )
  • Print the calculated sum.

SOLUTION : (Please use this as reference only)


CODE

Sunday 19 February 2017

IO 7

QUESTION DESCRIPTION :

Write a program to scan the given input and perform unary prefix increment and decrement operators.

Condition :

Variable name to be used:

Preadd, Presub, Posadd, Possub

Input and Output Format:

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output.



TEST CASE 1


INPUT

1

OUTPUT

2
1
1
2



EXPLANATION :

The objective of the code is to receive an integer input form the user and print the pre-increment , pre-decrement , post-increment , post-decrement values of the input received from the user. (Increment and Decrement Operators)


ALGORITHM :

  • Take an input from the user ( a )
  • Take pre increment of the value ( ++a )
  • Take pre decrement of the value ( --a )
  • Take post increment of the value ( a++ )
  • Take ppst decrement of the value ( a-- )
  • Store them in the variables and print ( Preadd,Presub,Posadd,Possub


SOLUTION : (Please use this as reference only)

CODE

IO 24

QUESTION DESCRIPTION :


Selvan from SRM Public school is studying 3r grade in school, her maths mam gave her a problem to convert the decimal number in octal and hexadecimal . Since her mam gave so much problems to solves.She went to his brother who is computer programmer and requested to create a program that converts automatically given integer to decimal, octal and hexadecimal equivalent. Let us help an programmer to do program?

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output.


TEST CASE 1


INPUT

25

OUTPUT

Decimal value:25
Octal value:31
Hexadecimal value:19


TEST CASE 2


INPUT

29

OUTPUT

Decimal value:29
Octal value:35
Hexadecimal value:1d

EXPLANATION :


The objective of this code is to accept an integer value from the user and print its octal ( decimalTOoctal ) and hexadecimal counterparts ( decimalTOhexadecimal )


ALGORITHM :

For OCTAL :
  • Accept the given number as integer( a )
  • If the number is less than 8, print the exact number as answer
  • If the number is > 8 , take the modulus by 8 and save the remainder in an array ( octal[] )
  • Do the above steps again but replace the number with the quotient , until you get a quotient less than 8.
  • Print the remainders in reverse order (bottom to top)
  • The result is the octal of the given decimal number.
 For HEXADECIMAL :
  • Accept the given number as integer( a )
  • If the number is less than 10, print the exact number as answer
  • If the number is > 10 and less than 16 , convert it to a character (10 is a , 11 is b ...).
  •  If the number is > 16 , take the modulus by 16 and save the remainder in an array ( hexad[] )
  • Do the above steps again but replace the number with the quotient , until you get a quotient less than 16.
  • Print the remainders in reverse order (bottom to top)
  • The result is the hexadecimal of the given decimal number.
SOLUTION : (Please use this as reference only)


CODE

IO 21

QUESTION DESCRIPTION :


Write a program to convert a floating point number into corresponding integer

Input and Output Format:

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output.


TEST CASE 1


INPUT

12.01

OUTPUT

The integer variant of 12.01 is=12


TEST CASE 2


INPUT

23.00

OUTPUT

The integer variant of 23.00 is=2


EXPLANATION :


The objective of this code is to accept a float value from the user and print its integer counterpart.


ALGORITHM :

  • Accept a float value from the user ( f )
  • Convert the float value to integer ( Type Casting )
  • Print the output value in the required format.
SOLUTION : (Please use this as reference only)

CODE





IO 23

QUESTION DESCRIPTION :

Mr.Right is an English teacher , he got task to to calculate a students result

based on input of two examinations ,one sport event , and three activities

conducted . Please help him to find the result of every individual section

according to weightage(Given below) provided by principal that results to

exam percent, sports percent,activities percent and finally total percent

that sums all individual result with following conditions met

Weightage:

ACTIVITIES_WEIGHTAGE- 30
SPORTS_WEIGHTAGE- 20
EXAMS_WEIGHTAGE -50

Total :

EXAMS_TOTAL out of 200
ACTIVITIES_TOTAL out of 60
SPORTS_TOTAL out of 50

Input Format :

Two scores obtained in two examination (out of 100)
The score obtained in sports events (out of 50)
The score obtained in three activities (out of 20)

Explanation :

To calculate exam percent=(Addition of two exam marks)*(Weightage of Exam) /(Total_score based on no of exam inputs).


TEST CASE 1


INPUT

78 89
34
19 18 17


OUTPUT

Result
Total Percent in examination:41.75
Total Percent in activities:27.00
Total Percent in sports:13.60
Total Percentage:82.35


EXPLANATION :

The objective of this code is to evaluate the marks of a student on the basis of the given criteria.The input will be 5 different numbers , first 2 values for exam score, next value for sports score and last 3 values for activity score.The output is the result card which contains individual percentage of the 3 categories and the sum of all three categories as total percentage.

Formula: (To calculate the individual percent of a category)

( Sum of all the scores in that category )*( Weightage of that category )/( Total maximum score of that activity )

example : (Calculating individual % for Activities, sample input : (19,18,17) )

( 19+18+17 )*( 30 )/( 60 )=27.00


ALGORITHM :
  • Accept all 5 inputs from user ( e1,e2,s,a1,a2,a3 )
  • Sum all individual categories ( e1+e2 , s , a1+a2+a3 )
  • Calculate individual percentage using formula ( ep,sp,ap )
  • Calculate total percentage ( ep+ap+sp )
  • Print the result in the expected format correct to 2 decimal places( %0.2f )
SOLUTION : (Please use this as reference only)

CODE





IO 18

QUESTION DESCRIPTION :

Write a program to convert Fahrenheit into Celsius

Input and Output Format:

Refer sample input and output for formatting specification.

All float values are displayed correct to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output.



TEST CASE 1


INPUT

0

OUTPUT

-17.78C


TEST CASE 2


INPUT

25.23


OUTPUT

-3.76C


EXPLANATION :

The objective of this code is to convert a given Fahrenheit input temperature to Celsius.The input is a float value provided by the user , which needs to be converted and printed.The formula needed is.


Formula

ALGORITHM :
  • Input a float value from user ( Input the temperature ).
  • Convert the temperature to Celsius ( c=(f-32)/1.8000 ).
  • Output the result correct to 2 decimal places(%.2f)


SOLUTION : (Please use this as reference only)


CODE


Saturday 18 February 2017

Introduction to C language

C  is a computer programming language, supporting structured programming, lexical variable scope and recursion.
C was originally developed by Dennis Ritchie between 1969 and 1973 at Bell Labs. It has become one of the most widely used programming languages of all time.

Resources that you can use to learn the C language:


Basic structure of a C program:


Hello World !
Now , lets get started with eLAB questions.

Good Luck to all.