In this tutorial you will learn about the C Program to Convert Kilogram to Gram and its application with practical example.
C Program to Convert Kilogram to Gram
In this tutorial, we will learn to create a C program that will Convert Kilogram to Gram in C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
Program to Convert Kilogram to Gram
As we all know the c is a very powerful language. With the help of c programming language, we can make many programs. We cal perform many input-output operations using c programming. In today’s tutorial, we take the input in kilograms from the user and convert it into grams. With the help of c programming, we can perform many conversion operations.
With the help of this program, we can Convert Kilogram to Gram.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declare the variables for the program. 2. Takeing the input number from the user for the program. 3. Passing that input for calculations. 4. Print the Result. 5. End the program. |
Program to Convert Kilogram to Gram:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/* Program to convert the kilo-grams input into the grams output */ #include<stdio.h> int main() { /*declaring the variables for the program */ float kg, g; /*taking the input from the user in kilo-grams*/ printf("Enter weight in Kilogram: "); /*scanning the input from the user*/ scanf("%f", &kg); /*Coverting the kilo-grams into grams.*/ g = kg*1000; /* Printing the result in grams converted with the help of program */ printf("Equivalent weight in Gram = %0.2f", g); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- kg = it will hold the float value for the program as an input from the user.
- g = it will hold the float value that will hold the grams converted in the program.
Taking the input from the user in the form of kilograms.
Printing the converted output from kilograms to grams.