Programming Fundamentals: Operator & Expression (Session 2)
Alice
Alice was bored that day,so she was sitting on the riverbank .Suddenly she notices a talking, White Rabbit with a pocket watch .It ran fast,and she followed it, down a rabbit hole .She fell into the hole and found a magical wonderland with dark trees, beautiful flowers.She found many ways numbered from 1,2,3,........18.she was confused which is the right way that will lead her to her home. She found a cute bird, standing in one of the tree. Alice asked the bird the way to go back to her home.The bird said a two digit number( say 23 ) and asked her to find the sum of its digits (2+3=5) and that numbered way will lead her to her home.Alice was already confused, so pls help Alice in finding the route to her home....
Input Format:
Input consists of an integer corresponding to the 2-digit number.
Output Format:
Output consists of an integer corresponding to the sum of its digits. Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to output]
SAMPLE INPUT OUTPUT 1 :
The bird said:
23
Alice must go in path-5 to find her way to home
SAMPLE INPUT OUTPUT 2 :
The bird said:
99
Alice must go in path-18 to find her way to home
#include<stdio.h>int main(){int n=0;printf("The bird said:\n");scanf("%d",&n);int sum=0;sum=n%10;n=n/10;sum=sum+n%10;printf("Alice must go in path-%d to find her way to home",sum);return 0;}
AVERAGE SALE
AVERAGE SALE
A grocer has a sale of Rs. s1, Rs. s2, Rs. s3, Rs. s4 and Rs. s5 for 5 consecutive months. How much sale must he have in the sixth month so that he gets an average sale of Rs. x?
Write a C program to compute the sale in the 6th month.
Input Format:
Input consists of 5 integers and 1 float. The five integers correspond to s1, s2, s3, s4 and s5. The float input corresponds to x.
Output Format:
Refer sample input and output for formatting specifications.
The float values are displayed correct to 2 decimal places.
Sample Input and Output:
[All text in bold corresponds to input and the rest corresponds to output]
Enter sale in first month
6435
Enter sale in second month
6927
Enter sale in third month
6855
Enter sale in fourth month
7230
Enter sale in fifth month
6562
Enter the average sales in 6 months
6500
The sale in the sixth month is Rs.4991.00
#include<stdio.h>int main(){float s1,s2,s3,s4,s5,s6;printf("Enter sale in first month\n");scanf("%f",&s1);printf("Enter sale in second month\n");scanf("%f",&s2);printf("Enter sale in third month\n");scanf("%f",&s3);printf("Enter sale in fourth month\n");scanf("%f",&s4);printf("Enter sale in fifth month\n");scanf("%f",&s5);printf("Enter the average sales in 6 months\n");scanf("%f",&s6);printf("The sale in the sixth month is Rs.%.2f",(6*s6)-s1-s2-s3-s4-s5);return 0;}
FENCING THE GROUND
FENCING THE GROUND
The college ground is rectangular in shape. The Management decides to build a fence around the ground. In order to help the construction workers to build a straight fence, they planned to place a thick rope around the ground. They wanted to buy only the exact length of the rope that is needed. They also wanted to cover the entire ground with a thick carpet during rainy season. They wanted to buy only the exact quantity of carpet that is needed. They requested your help.
Can you please help them by writing a C program to find the exact length of the rope and the exact quantity of carpet that is needed?
Input Format:
Input consists of 2 integers. The first integer corresponds to the length of the ground and the second integer corresponds to the breadth of the ground.
Output Format:
Refer Sample Input and Output for exact formatting specifications.
Sample Input and Output:
[All text in bold corresponds to input and the rest corresponds to output]
Enter the length of the ground
50
Enter the width of the ground
20
The length of the rope needed is 140m
The quantity of carpet needed is 1000sqm
#include<stdio.h>int main(){int l=0,b=0;printf("Enter the length of the ground\n");scanf("%d",&l);printf("Enter the width of the ground\n");scanf("%d",&b);printf("The length of the rope needed is %dm\n",2*(l+b));printf("The quantity of carpet needed is %dsqm",l*b);return 0;}
FOUR SEASONERS
FOUR SEASONERS
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 fouth integers correspond to x2 and y2 respectively.
The fifth and sixth integers correspond to x3 and y3 respectively.
Output Format:
Refer Sample Input and Output for exact formatting specifications.
[All floating point values are displayed correct to 1 decimal place]
Sample Input and Output:
[All text in bold corresponds to input and the rest corresponds to output]
Enter x1
2
Enter y1
4
Enter x2
10
Enter y2
15
Enter x3
5
Enter y3
8
Dinesh's house is located at (5.7 , 9.0)
#include<stdio.h>int main(){float x1,x2,x3,y1,y2,y3;printf("Enter x1\n");scanf("%f",&x1);printf("Enter y1\n");scanf("%f",&y1);printf("Enter x2\n");scanf("%f",&x2);printf("Enter y2\n");scanf("%f",&y2);printf("Enter x3\n");scanf("%f",&x3);printf("Enter y3\n");scanf("%f",&y3);printf("Dinesh's house is located at (%.1f , %.1f)",(x1+x2+x3)/3,(y1+y2+y3)/3);return 0;}
INTERCEPTS
INTERCEPTS
Emily is a very popular Maths Teacher in School. She retires from her service today. Her 7th class students like her very much and they wanted to give her a grand farewell at school. The school HeadMistress is a very strict person and she didn't give permission for them to conduct the farewell in the school premises. The students decided to conduct the farewell at Emily Mam's house itself.
They know the street in which Emily mam lives. The student leader asked Emily Mam to tell her house number. Emily Mam's last class was on Equation for a straight line. She said that a straight line can be represented by the equation y=mx+c and you know how to find the x-intercept and y-intercept of the line and my house number is the sum of the x-intercept and y-intercept of the line.
The students were puzzled. Can you help the students find the house number of Emily Mam?
Given the values of m and c of the line equation y=mx+c, write a C program to find the sum of x-intercept and y-intercept.
Input Format:
Input consists of 2 integers. The first integer corresponds to m and the second integer corresponds to c.
Output Format:
Refer Sample Input and Output for exact formatting specifications.
[Assume that the inputs are such that the intercept values are always integers]
Sample Input and Output:
[All text in bold corresponds to input and the rest corresponds to output]
Enter the value of m
5
Enter the value of c
10
The line equation is y=5x+10
The x intercept is -2
The y intercept is 10
The house number is 8
#include<stdio.h>int main(){int m=0,c=0;printf("Enter the value of m\n");scanf("%d",&m);printf("Enter the value of c\n");scanf("%d",&c);printf("The line equation is y=%dx+%d\nThe x intercept is %d\nThe y intercept is %d\nThe house number is %d",m,c,-(c/m),c,c-(c/m));return 0;}
PLACING THE FLAG POST
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.
Output Format:
Refer Sample Input and Output for exact formatting specifications.
Sample Input and Output:
[All text in bold corresponds to input and the rest corresponds to output]
Enter the x-coordinate of the left bottom vertex
4
Enter the y-coordinate of the left bottom vertex
O
Enter the length of a side
8
The centre of the ground is at (8,4)
#include<stdio.h>int main(){int x=0,y=0,z=0;printf("Enter the x-coordinate of the left bottom vertex\n");scanf("%d",&x);printf("Enter the y-coordinate of the left bottom vertex\n");scanf("%d",&y);printf("Enter the length of a side\n");scanf("%d",&z);printf("The centre of the ground is at (%d,%d)",x+z/2,y+z/2);return 0;}
PROFIT CALCULATOR
Each Sunday, a newspaper agency sells x copies of a certain newspaper for Rs.a per copy. The cost to the agency of each newspaper is Rs.b . The agency pays a fixed cost for storage, delivery and so on of Rs.100 per Sunday. The newspaper agency wants to calculate the profit obtained on sundays. Can you please help them out by writing a C program to compute the profit given x, a and b.
Input Format:
Input consists of 3 integers --- x, a and b. X is the number of copies sold, a is the cost per copy and b is the cost the agency spends per copy.
Output Format:
Refer Sample Input and Output for exact formatting specifications.
Sample Input and Output:
[All text in bold corresponds to input and the rest corresponds to output]
Enter the number of copies sold
1000
Enter the cost of 1 copy of the newspaper
2
Enter the cost spent by the agency on 1 copy of the newspaper
1
The profit obtained is Rs.900
#include<stdio.h>int main(){int a,b,c;printf("Enter the number of copies sold\n");scanf("%d",&a);printf("Enter the cost of 1 copy of the newspaper\n");scanf("%d",&b);printf("Enter the cost spent by the agency on 1 copy of the newspaper\n");scanf("%d",&c);printf("The profit obtained is Rs.%d",((b-c)*a)-100);return 0;}
Split
Splitting into Teams
During the Physical Education hour, PD sir Mr. Sundar 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.
PD 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.
Output Format:
Refer sample input and output for formatting specifications.
Sample Input and Output:
[All text in bold corresponds to input and the rest corresponds to output]
Enter the number of students in the class
60
Enter the number of teams
8
The number of students in each team is 7 and the number of students left out is 4
#include<stdio.h>int main(){int a=0,b=0;printf("Enter the number of students in the class\n");scanf("%d",&a);printf("Enter the number of teams\n");scanf("%d",&b);printf("The number of students in each team is %d and the number of students left out is %d",a/b,a%b);return 0;}
THREE IDIOTS
Ajay, Binoy and Chandru were very close friends at school. They were very good in Mathematics and they were the pet students of Emily Mam. Their gang was known as 3-idiots. Ajay, Binoy and Chandru live in the same locality.
A new student Dinesh joins their class and he wanted to be friends with them. He asked Binoy about his house address. Binoy wanted to test Dinesh's mathematical skills. Binoy told Dinesh that his house is at the midpoint of the line joining Ajay's house and Chandru's house. Dinesh was puzzled. Can you help Dinesh out?
Given the coordinates of the 2 end points of a line (x1,y1) and (x2,y2), write a C program to find the midpoint of the line.
Input Format:
Input consists of 4 integers. The first integer corresponds to x1 . The second integer corresponds to y1. The third and fouth integers correspond to x2 and y2 respectively.
Output Format:
Refer Sample Input and Output for exact formatting specifications.
[All floating point values are displayed correct to 1 decimal place]
Sample Input and Output:
[All text in bold corresponds to input and the rest corresponds to output]
Enter x1
2
Enter y1
4
Enter x2
10
Enter y2
15
Binoy's house is located at (6.0 , 9.5)
#include<stdio.h>int main(){float x1=0,y1=0,x2=0,y2=0;printf("Enter x1\n");scanf("%f",&x1);printf("Enter y1\n");scanf("%f",&y1);printf("Enter x2\n");scanf("%f",&x2);printf("Enter y2\n");scanf("%f",&y2);printf("Binoy's house is located at (%.1f , %.1f)",(x1+x2)/2,(y1+y2)/2);return 0;}
TRIANGLE SIDES
The mathematics teacher has recently taught the formula for computing the distance between 2 points to her students. She gave them an asssignment on calculating the distance between the points. In order to prevent copying, she gave each student a different set of questions. But she found it very difficult to correct all 100 assignments. She seeks your help. Can you please help her out?
Given the vertices of a triangle ABC, determine the sides of the triangle AB, BC and AC. Can you write a C program to calculate the sides?
Input Format
Input consists of 6 integers. The first 2 integers correspond to the x-coordinate and y-coordinate of vertex A. The next 2 integers correspond to the x-coordinate and y-coordinate of vertex B. The next 2 integers correspond to the x-coordinate and y-coordinate of vertex C.
Output Format:
Refer Sample Input and Output for exact formatting specifications.
[All floating pont values are displayed correct to 1 decimal place]
Sample Input and Output:
[All text in bold corresponds to input and the rest corresponds to output]
Enter the x-coordinate of vertex A
5
Enter the y-coordinate of vertex A
10
Enter the x-coordinate of vertex B
10
Enter the y-coordinate of vertex B
10
Enter the x-coordinate of vertex C
8
Enter the y-coordinate of vertex C
4
Length of side AB is 5.0
Length of side BC is 6.3
Length of side AC is 6.7
#include<stdio.h>#include<math.h>int main(){int xa=0,xb=0,xc=0,ya=0,yb=0,yc=0;printf("Enter the x-coordinate of vertex A\n");scanf("%d",&xa);printf("Enter the y-coordinate of vertex A\n");scanf("%d",&ya);printf("Enter the x-coordinate of vertex B\n");scanf("%d",&xb);printf("Enter the y-coordinate of vertex B\n");scanf("%d",&yb);printf("Enter the x-coordinate of vertex C\n");scanf("%d",&xc);printf("Enter the y-coordinate of vertex C\n");scanf("%d",&yc);printf("Length of side AB is %.1f\n",sqrt(((xa-xb)*(xa-xb))+((ya-yb)*(ya-yb))));printf("Length of side BC is %.1f\n",sqrt(((xb-xc)*(xb-xc))+((yb-yc)*(yb-yc))));printf("Length of side AC is %.1f\n",sqrt(((xa-xc)*(xa-xc))+((ya-yc)*(ya-yc))));return 0;}
Post a Comment