0% found this document useful (0 votes)
5 views3 pages

Program 1 & Program 2

The document contains two C programs: one for calculating the mechanical energy of a particle using the formula E = mgh + (1/2)mv², and another for converting kilometers into meters, centimeters, and millimeters. It also includes expected viva questions related to computer concepts, C programming, and the specifics of the programs. Key topics covered include input/output operations, data types, and the roles of functions like printf() and scanf().

Uploaded by

patilsumanth8842
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Program 1 & Program 2

The document contains two C programs: one for calculating the mechanical energy of a particle using the formula E = mgh + (1/2)mv², and another for converting kilometers into meters, centimeters, and millimeters. It also includes expected viva questions related to computer concepts, C programming, and the specifics of the programs. Key topics covered include input/output operations, data types, and the roles of functions like printf() and scanf().

Uploaded by

patilsumanth8842
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1. C Program to find Mechanical Energy of a particle using E = mgh+1/2 mv2.

 Concepts: Variables, mathematical operations, and input/output.


 Explanation: Use the formula E = mgh + (1/2)mv² to calculate mechanical energy,
where you input values for mass (m), gravity (g), height (h), and velocity (v).
 Input/Output: Use scanf() to take inputs and printf() to display the result.

#include <stdio.h>
int main()
{
float m, h, v, p, k, e;
printf("Enter Mass of the body\n");
scanf("%f", &m);
printf("Enter displacement of the body\n");
scanf("%f", &h);
printf("Enter velocity of the body\n");
scanf("%f", &v);
p = m * 9.8 * h;
k = 0.5 * m * (v * v);
e = p + k;
printf("Potential energy of the body = %f\n", p);
printf("Kinetic energy of the body = %f\n", k);
printf("Mechanical energy of the body = %f\n", e);
return 0;
}
2. C Program to convert kilometer into meter, centimeter and millimeter.
 Concepts: Simple arithmetic calculations and input/output.
 Explanation: Convert kilometers to meters (1 km = 1000 meters) and centimeters (1
meter = 100 cm) by using the conversion formulas.
 Input/Output: Take input for kilometers and print meters and centimeters.

#include <stdio.h>
int main()
{
float km, cm, mm, m;
printf("Enter the distance in Kilometer: ");
scanf("%f", &km);
m = km * 1000.0;
cm = km * 100000.0;
mm = km * 1000000.0;
printf("Distance in meter is %f\n", m);
printf("Distance in centimeter is %f\n", cm);
printf("Distance in millimeter is %f\n", mm);
return 0;
}
Expected Viva Questions:
1. What is a computer?
A computer is an electronic device that processes data according to a set of instructions to
perform tasks.
2. What are input and output devices?
Input devices (e.g., keyboard, mouse) allow users to enter data into the computer, while
output devices (e.g., monitor, printer) display or produce the result of computer operations.
3. What is C programming, and why is it important?
C is a general-purpose programming language known for its efficiency and control over
system resources. It is often used for developing system software and embedded systems.
4. What are the basic components of a C program?
A typical C program includes header files (#include), a main() function, declarations, and
statements.
5. What is the purpose of header files in a C program?
Header files contain function declarations and macros, which are used to include standard
functions and libraries in a program.
6. What is a compiler, and what is its role?
A compiler is a tool that translates C code into machine code, which the computer can
execute.
7. What are variables and constants?
Variables are memory locations used to store data that can change during program execution,
while constants hold fixed values that do not change.
8. What is the syntax of a printf() statement in C?
The printf() function is used to output data to the console, for example: printf("Hello,
World!");.
9. How do you take input from the user in C?
The scanf() function is used to read input from the user, for example: scanf("%d",
&variable);.
10. What are some examples of data types in C?
Common data types include int, float, char, and double.

C Program to Find Mechanical Energy of a Particle


1. What is mechanical energy?
Mechanical energy is the sum of potential energy (mgh) and kinetic energy (1/2 mv²) of an
object.
2. What is the formula for calculating mechanical energy?
E = mgh + (1/2)mv², where m is mass, g is acceleration due to gravity, h is height, and v is
velocity.
3. What are the inputs required for this program?
The inputs are m (mass), g (acceleration due to gravity), h (height), and v (velocity).
4. Which data type would you use to store the values of mass, height, and velocity?
Typically, float or double is used to store these values to account for decimal values.
5. Why do we use printf() and scanf() in this program?
scanf() is used to read input values from the user, while printf() is used to display the result
(mechanical energy).

C Program to Convert Kilometers into Meters and Centimeters


1. What is the conversion factor from kilometers to meters?
1 kilometer = 1000 meters.
2. What is the conversion factor from meters to centimeters?
1 meter = 100 centimeters.
3. Why do we need to convert kilometers into meters and centimeters?
This conversion is often needed for consistency in measurements and calculations where a
smaller unit is required.
4. How do you declare variables for storing distance in kilometers, meters, and
centimeters?
Typically, float or double is used for more precise distance measurements.
5. What would be the output if you enter 2.5 kilometers in your program?
The output would be:
 Meters: 2500
 Centimeters: 250000
6. How does the scanf() function work in this program?
scanf() reads the input value for kilometers from the user and stores it in the corresponding
variable.
7. What is the role of arithmetic operators in this conversion program?
Arithmetic operators (*) are used to multiply kilometers by 1000 to get meters, and meters by
100 to get centimeters.
8. Can we use the same variable for storing both kilometers and meters? Why or why
not?
It is not ideal to use the same variable as they represent different units, and it would make the
program less readable and prone to errors.
9. What are some possible input validation checks for this program?
Checks to ensure that the input for kilometers is a positive number, as distance cannot be
negative.
10. How would you modify the program to handle multiple conversions in a loop?
Use a while or for loop to allow the user to enter multiple values for conversion until they
decide to stop.

You might also like