You are on page 1of 3

# To convert some formulas in C program using switch case..........

// Online C compiler to run C program online


#include <stdio.h>
int main() {
int number,a;
printf("------------\n");
printf("instructions\n");
printf("-------------\n");
printf("\n");
printf("\n......convert....\n");
printf("1. kms to meters --> enter 1 \n");
printf("2. inches to foot --> enter 2\n");
printf("3. cms to inches --> enter 3\n");
printf("4. inches to meter --> enter 4\n");
printf("enter number given in instruction : ");
scanf("%d",&number);
switch(number)
{
case 1:
{
printf("Enter any number that you convert:");
scanf("%d",&a);
printf("the kms to meter is :%d",a*1000);
break;
}
case 2:
{
printf("enter any number that you convert inches to foot: : ");
scanf("%d",&a);
printf("The inches to foot is : %0.4f",(float)1/12*a);
break;
}
case 3:
{
printf("Enter any number that you convert cms to inchs: ");
scanf("%d",&a);
printf("convert cms to inchs : %0.4f",(float)a*0.393701);
break;
}
case 4:
{
printf("enter any number that you convert inches to meters : ");
scanf("%d",&a);
printf("convert inches to meters : %0.4f",(float)a*0.0254);
break;
}
default:
{
printf("error");
}
}
return 0;
}

# To convert some formulas in C program using if else if ladder.........

#include <stdio.h>

int main() {
// Write C code here
int a,b;
printf("----------------------\n");
printf(" CONVERSION \n");
printf("------------------------\n");
printf("\n");
printf("km to meter-->enter 1\n");
printf("inch to foot-->enter 2\n");
printf("cm to inch-->enter 3\n");
printf("inch to meter-->enter 4\n");
printf("pound to kgs-->enter 5\n");
printf("enter any number:");
scanf("%d",&a);
if(a==1)
{
printf("enter the number that you convert km to meter:");
scanf("%d",&b);
printf("km to meter is :%d",b*1000);
}
else if(a==2)
{
printf("enter the number that you convert inch to foot: ");
scanf("%d",&b);
printf("inch to foot is :%0.4f",(float)b*0.08333);
}
else if(a==3)
{
printf("enter the number that you convert cm to inchs :");
scanf("%d",&b);
printf("cm to inch : %0.4f",(float)b*0.393701);
}
else if(a==4)
{
printf("enter the number that you convert inches to meter :");
scanf("%d",&b);
printf("inch to meter: %0.4f",(float)b*0.0254);
}
else if(a==5)
{
printf("enter the number that you convert pound to kgs :");
scanf("%d",&b);
printf("pound to kgs :%0.4f",(float)b*0.453592);
}
else{
printf("!! enter number is incorrect !!");
}

return 0;
}

You might also like