The document provides instructions to write a C program to find the midpoint of a line given the coordinates of its two endpoints. It gives the input format as four integers representing x1, y1, x2, y2 and the output format as the midpoint coordinates within parentheses and to one decimal place. It includes a sample input and output.
Unlocking Growth The Power of Outsourcing for CPA Firms
Module 1 programs
1. --- PROBLEM DESCRIPTION - M2P1 - 4 - Splitting into Teams ---
Splitting into Teams
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.
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]
Number of students:
60
Number of teams:
8
The number of students in each team is 7 and left out is 4
-----------------------------------------------------------------------------------------------------------------------
2. --- ALGORITHM - M2P1 - 4 - Splitting into Teams ---
Step 1: Start the program.
Step 2: Read the number of students [a] and number of teams [b] as from the user.
Step 3: Use a/b to calculate the number of students in each team and a % b to calculate the left out students.
Step 4: Display the result to the user
Step 5: Stop the program
-----------------------------------------------------------------------------------------------------------------------
4. --- PROGRAM - M2P1 - 4 - Splitting into Teams---
# include <stdio.h>
int main()
{
int n, t;
printf(" Number of students :n");
scanf("%d", &n);
printf("Number of teams:n");
scanf("%d", &t);
int m, l;
m = n / t;
l = n % t;
printf("The number of students in each team is %d and left out is %d", m, l);
return 0;
}
-----------------------------------------------------------------------------------------------------------------------
Result:
Thus the C Program for splitting the number of students into team was executed and verified
successfully.
5. --- PROBLEM DESCRIPTION - Odd or Even using Bitwise and Operator ---
Odd or Even using Bitwise and Operator
Write a C program to find whether the given number is odd or even, using Bitwise ' & ' Operator.
Input Format:
The input consists of an integer.
Output Format:
Output should display whether the input is Odd or Even.
Refersample input and output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to output]
Sample Input and Output 1:
Enter the number :
5
Odd
Sample Input and Output 2:
Enter the number :
8
Even
-----------------------------------------------------------------------------------------------------------------------
6. --- ALGORITHM - Odd or even using Bitwise and Operator ---
Step 1: Start the process.
Step 2: Declare and get the values for a,b,c.
Step 3: Use n & 1 to check whether the given number is odd or even
Step 4: Display the result to the user
Step 5: Stop the program
-----------------------------------------------------------------------------------------------------------------------
8. --- PROGRAM - Odd or even using Bitwise and Operator---
# include <stdio.h>
int main()
{
int a;
printf("Enter the number :n");
scanf("%d", &a);
(a & 1) ? printf("Odd n") : printf("Even n");
return 0;
}
-----------------------------------------------------------------------------------------------------------------------
Result:
Thus the C Program for finding whether the given number is odd or even using bitwise operator was
executed and verified successfully.
9. --- PROBLEM DESCRIPTION - Largest of three numbers using Ternary Operator ---
Largest of three numbers using Ternary Operator
Write a program to find greatest of three numbers, using Ternary Operator.
Input Format:
The input consists of 3 integers.
Output Format:
Output should display the greatest of the 3 numbers.
Refersample input and output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to output]
Sample Input and Output 1:
Enter the numbers:
5
8
2
8 is the greatest number
Sample Input and Output 2:
Enter the numbers:
44
16
23
44 is the greatest number
-----------------------------------------------------------------------------------------------------------------------
10. --- ALGORITHM - Largest of three numbers using Ternary Operator ---
Step 1: Start the process.
Step 2: Initialize variables a,b,c and d. Get the values of a,b,c from user.
Step 3: Using ternary operator find the greatest among 3 numbers and store the value in
big.
Step 4: Display the value of big.
Step 5: Stop the process.
-----------------------------------------------------------------------------------------------------------------------
11. --- FLOWCHART - Largest of three numbers using Ternary Operator ---
12. --- PROGRAM - Largest of three numbers using Ternary Operator---
# include <stdio.h>
int main()
{
int a, b, c;
printf("Enter the numbers:n");
scanf("%d %d %d", &a, &b, &c);
int big;
big = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
printf("%d is the greatest number", big);
return 0;
}
-----------------------------------------------------------------------------------------------------------------------
Result:
Thus the C Program for finding largest of three numbers using ternary operator was executed and
verified successfully.
13. --- PROBLEM DESCRIPTION - M2P2 - 7 - THREE IDIOTS ---
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 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]
X1
2
Y1
4
X2
10
Y2
15
Binoy's house is located at (6.0,9.5)
-----------------------------------------------------------------------------------------------------------------------
14. --- ALGORITHM - M2P2 - 7 - THREE IDIOTS ---
Step 1:Start the process.
Step 2:Declare and get the values for x1,y1,x2,y2.
Step 3:Declare and calculate x3=(x1+x2)/2 and y3=(y1+y2)/2.
Step 4:Display the result.
Step 5:Stop the process.
-----------------------------------------------------------------------------------------------------------------------
16. --- PROGRAM - M2P2 - 7 - THREE IDIOTS---
#include<stdio.h>
int main()
{
int x1, x2, y1, y2;
char c1 = '(';
char c2 = ')';
printf("X1n");
scanf("%d", &x1);
printf("Y1n");
scanf("%d", &y1);
printf("X2n");
scanf("%d", &x2);
printf("Y2n");
scanf("%d", &y2);
float x3 = ((x1 + x2) / 2.0);
float y3 = ((y1 + y2) / 2.0);
printf("Binoy's house is located at %c%.1f,%.1f%c", c1, x3, y3, c2);
return 0;
}
-----------------------------------------------------------------------------------------------------------------------
Result:
Thus the C Program for finding distance between two points was executed and verified successfully.
17. --- PROBLEM DESCRIPTION - Celsius to Fahrenheit Converter ---
Celsius to Fahrenheit Converter
The relatioship between Celsius (C) and Fahrenheit (F) degrees for measuring temperature is linear.
Find an equation relating C and F if 0 C corresponds to 32 F and 100 C corresponds to 212 F.
Write a program to simulate Celsius to Fahrenheit Converter.
Input Format:
Input consists of a single integer which corresponds to a measure of temparature in Celcius.
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]
Temparature in Celsius:
12
Temparature in Fahrenheit is 53.6F
-----------------------------------------------------------------------------------------------------------------------
18. --- ALGORITHM - Celsius to Fahrenheit Converter ---
Step 1: Start the process.
Step 2: Initialize c and f.
Step 3: Get the value of c from the user.
Step 3: Compute f= (c*9/5) +32.
Step 4: Print the result.
Step 5: Stop the process.
-----------------------------------------------------------------------------------------------------------------------
20. --- PROGRAM - Celsius to Fahrenheit Converter---
# include <stdio.h>
int main()
{
float c, f;
printf("Temparature in Celsius:");
scanf("n%f", &c);
f = (c * 9 / 5) + 32;
printf("nTemparature in Fahrenheit is %.1fF", f);
return 0;
}
-----------------------------------------------------------------------------------------------------------------------
Result:
Thus the C Program to convert the temperature from Celsius to Fahrenheit was executed and verified
successfully.
21. --- PROBLEM DESCRIPTION - quadratic equation roots ---
Quadratic Equation Roots
Write a program to find the roots of given quadratic equation. The
Quadratic equation is of the form ax2+bx+c = 0.
Input Format:
Input consists of 3 integer corresponding to a,b and c respectively.
Output Format:
Print the of the equation formed by the given values of a,b,c. Display the roots correct to 1 decimal place.
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to
output.]
Sample Input and Output:
Enter the values of a,b,c :
1
4
4
The roots are:
root1 = -2.0
root2 = -2.0
-----------------------------------------------------------------------------------------------------------------------
22. --- ALGORITHM - quadratic equation roots ---
Step 1: Start the process.
Step 2: Declare and get the values for a,b,c.
Step 3: Calculate root1=(-b+(b*b-4*a*c))/(2*a) and
root2=(-b-(b*b-4*a*c))/(2*a).
Step 4: Display the result.
Step 5: Stop the process.
-----------------------------------------------------------------------------------------------------------------------
24. --- PROGRAM - quadratic equation roots---
# include <stdio.h>
# include <math.h>
int main()
{
int a, b, c;
float root1, root2;
printf("Enter the values of a,b,c :");
scanf("%d %d %d", &a, &b, &c);
root1 = (-b + sqrt((b * b) - (4 * a * c))) / (2 * a);
root2 = (-b - sqrt((b * b) - (4 * a * c))) / (2 * a);
printf("nThe roots are:");
printf("nroot1 = %.1f", root1);
printf("nroot2 = %.1f", root2);
return 0;
}
-----------------------------------------------------------------------------------------------------------------------
Result:
Thus the C Program to find the roots of the quadratic equation was executed and verified successfully.