Write a program to convert kilogram to gram and pound.
● Declare an array as a global variable, called kilo with 4 elements.
● In main():
▪ Call function get_input().
▪ Call function convert_gram().
▪ Call function convert_pound().
● In get_input():
Using for loop, prompt the user to input the values in kilogram and store them in the
array kilo.
● In convert_gram():
▪ Use for loop to convert the values in grams and display the values.
▪ Formula: 1 kg = 1000 g
● In convert_pound():
▪ Use for loop to convert the values in pounds and display the values.
▪ Formula: 1 kg = 2.205 pounds
#include<stdio.h>
#include<conio.h>
float n[4];
void get_input(float n[]){
printf("enter the values, (in kilogram) \n");
for(int i=1;i<=4;i++){
scanf("%f",&n[i]);
}
for(int i=1;i<=4;i++){
printf("%0.2f",n[i]);
printf(" ");
}
}
void convert_gram(float n[]){
printf("\n\nThe conversion of kg to gram is given below \n \n");
for(int i=1;i<=4;i++){
printf("%0.2f ",n[i]*1000);
printf("gram ");
}
}
void convert_pound(float n[]){
printf("\n \n The conversion of kg to pound is given below \n \n");
for(int i=1;i<=4;i++){
printf("%0.2f",n[i]*2.205);
printf("pound ");
}
printf("\n");
}
int main(){
get_input(n);
convert_gram(n);
convert_pound(n);
return 0;
}
Comments
Leave a comment