C Exercise 2: Units and Conversions: C Tutorial In Hindi #22

preview_player
Показать описание
In this series of C programming tutorial videos, I have explained you everything you need to know about C language. I hope you are enjoying this C course in Hindi.

Best Hindi Videos For Learning Programming:

Follow Me On Social Media
Рекомендации по теме
Комментарии
Автор

Mazaa aa raha hai na course mei? Apne friends ke saath share karna mat bhoolna! :)

CodeWithHarry
Автор

C Exercise 2: Units and Conversions

code
#include <stdio.h>

int main()
{
int choice, km, inch, cm, pound ;

printf(" 1 for kms to miles\n 2 for inches to foot \n 3 for cms to inches\n 4 for pound to kgs\n 5 for inches to meters \n 6 for exit \n");

label:

printf(" Enter value of choice: ");
scanf("%d", &choice);

switch(choice)
{
case 1:
printf(" Enter value of kms: ");
scanf("%d", &km);

printf("%d kms is equal to %.4f Miles\n", km, 0.6214*km);
break;

case 2:
printf(" Enter value of inches: ");
scanf("%d", &inch);

printf("%d inches is equal to %.4f foot\n", inch, 0.0833*inch);
break;

case 3:
printf(" Enter value of Cms: ");
scanf("%d", &cm);

printf("%d Cms is equal to %.4f inches\n", cm, 0.394*cm);
break;

case 4:
printf(" Enter value of pounds: ");
scanf("%d", &pound);

printf("%d pounds is equal to %.4f kgs \n", pound, 0.454*pound);
break;

case 5:
printf(" Enter value of inches: ");
scanf("%d", &inch);

printf("%d inches is equal to %.4f metre \n", inch, 0.0254*inch);
break;

case 6:
{
return 0;

}
default :
printf(" Enter valid choices \n");
}
goto label ;
}
output:

1 for kms to miles
2 for inches to foot
3 for cms to inches
4 for pound to kgs
5 for inches to meters
6 for exit
Enter value of choice: 1
Enter value of kms: 1
1 kms is equal to 0.6214 Miles
Enter value of choice: 2
Enter value of inches: 1
1 inches is equal to 0.0833 foot
Enter value of choice: 3
Enter value of Cms: 1
1 Cms is equal to 0.3940 inches
Enter value of choice: 4
Enter value of pounds: 1
1 pounds is equal to 0.4540 kgs
Enter value of choice: 5
Enter value of inches: 1
1 inches is equal to 0.0254 metre
Enter value of choice: 7
Enter valid choices
Enter value of choice: 6

Process returned 0 (0x0) execution time : 51.663 s
Press any key to continue.

ANKIt_
Автор

*I just have seen only 21 leactures of you and i am able to do it all by my own*

#include <stdio.h>
int main()
{
int num, a;
float km, inch;

label:

printf(" Which one would you like to convert\n");
printf("Enter 1 for km to mile\n");
printf("Enter 2 for inch to foot\n");
// printf("Enter 3 for cm to inch\n");
// printf("Enter 4 for pound to kg\n");
// printf("Enter 5 for inch to mrter\n");

scanf("%d", &num);

switch (num)
{
case 1:

printf(" Enter the km\n");
scanf("%f", &km);
printf("%f km is equal to %f mile\n", km, 0.621 * km);
break;

case 2:

printf("Enter the inch\n");
scanf("%f", &inch);
printf("%f inch is equal to %f foot\n", inch, 0.393*inch);
break;

default:

printf("your entered number choice is not here\n");
}

end:

printf("enter 0 to exit and 9 to return to converter\n");
scanf("%d", &a);
if (a==0)
{
printf("you exited the program");
}
else if (a==9)
{
goto label;
}
else {
printf("oops! sorry, you entered the wrong number\n ");
goto end;
}

return 0;
}



thanks;

lokesh_
Автор

sir aapne c++ me recursion kaafi short me bataya tha so main in videos se c++ me seekh raha kaafi same hi hai samagh me aa raha ✌✌✌✌

adityamishra
Автор

Challenge completed.
I declared the functions. I made 10 conversion function(5 unit conversion and their counter conversion). In the main function, I took input from the user by presenting them with a list of the available conversions accompanied with a constant integer. After taking the input, the program goes to the corresponding conversion by switch case statement. Their it asks for the number to be converted and gives the output. The whole program is in a do-while loop, so it keeps on asking for conversion. The condition to get out of the loop is to enter zero in which case the program thanks the user and ends the program.
10 conversion, 120 lines of code, excluding comments.

barunjena
Автор

/*Perform The conversion of units
to convert kilometers to miles
to convert inches to foot
to convert centimeters to inches
to convert pounds to kgs
to convert inches to meters
By using switch case conditions in C Language*/
#include <stdio.h>
int main()
{
int choices;
float kilometers, miles, inches, foot, centimeters, pounds, kgs, meters;
char ch;
printf("Enter 'Y' if you want to perform conversions: \n");
printf("Enter 'N' if you donot want to perform conversions: \n");
scanf(" %c", &ch);
switch (ch)
{
case 'Y':
printf("Hi, Lets perform the conversions of units: \n");
printf("Enter 1 to convert kilometers to miles: \n");
printf("Enter 2 to convert inches to foot: \n");
printf("Enter 3 to convert centimeters to inches: \n");
printf("Enter 4 to convert pounds to kgs: \n");
printf("Enter 5 to convert inches to meters : \n");
scanf("%d", &choices);
switch (choices)
{
case 1:
printf("Enter kilometers: \n");
scanf("%f", &kilometers);
miles = kilometers * 0.621371;
printf("It is converted to miles at: %f\n", miles);
break;
case 2:
printf("Enter inches: \n");
scanf("%f", &inches);
foot = inches * 0.08333;
printf("It is converted to foot at: %f\n", foot);
break;
case 3:
printf("Enter centimeters: \n");
scanf("%f", &centimeters);
inches = centimeters * 0.393701;
printf("It is converted to inches at: %f\n", inches);
break;
case 4:
printf("Enter pounds: \n");
scanf("%f", &pounds);
kgs = pounds * 0.453592;
printf("It is converted to kgs at: %f\n", kgs);
break;
case 5:
printf("Enter inches: \n");
scanf("%f", &inches);
meters = inches * 39.37;
printf("It is converted to meters at: %f\n", meters);
break;
default:
printf("!!Wrong choice!! \n");
break;
}
main();
break;
case 'N':
printf("You decided not to convert anything. \n");
printf("Thanks for visit.\nHave a Nice Day!\n");
break;
default:
printf("You Entered a Wrong Character!\n");
break;
}
return 0;
}

ishtiaqahmed
Автор

challenge excepted!!!!
dude the way u teaches hats off to u r social work

teetayashkale
Автор

Late hu but still challenge accepted
Thank sir for this classes
It helps a lot more than any paid class

abhisheksutar
Автор

#include<stdio.h>
int main()
{
int choice;
float miles, foot, inches, kg, meters, km, inch, cm, pound, i;

int ch;
printf("Enter 1 if you want to perform conversions:\n");
printf("Enter 2 if you do not want to perform conversions:\n");
scanf("%d", &ch);
switch(ch)
{
case 1:printf("Lets perform conversions of units:)\n");

//Lets do conversion of units
printf("Enter 1 to convert kilometers to miles\n");
printf("Enter 2 to convert inches to foot\n");
printf("Enter 3 to convert centimeters to inches\n");
printf("Enter 4 to convert pound to kilogramms\n");
printf("Enter 5 to convert inches to meters\n");
scanf("%d", &choice);
switch(choice)
{
case 1:printf("Enter the given kilometers:");
scanf("%f", &km);
miles=km*0.621371;
printf("Its conversion in miles is %f", miles);
break;

case 2:printf("Enter the given inches:");
scanf("%f", &inch);
foot=inch*0.08333;
printf("Its conversion in foot is %f", foot);
break;

case 3:printf("Enter the given centimeters:");
scanf("%f", &cm);
inches=cm*0.393701;
printf("Its conversion in inches is %f", inches);
break;

case 4:printf("Enter the given pound:");
scanf("%f", &pound);
kg=pound*0.453592;
printf("Its conversion in kilograms is %f", kg);
break;

case 5:printf("Enter the given inches:");
scanf("%f", &i);
meters=i*0.0254;
printf("Its conversion in meters is %f", meters);
break;

default:printf("Wrong Choice!!");
break;

}
break;

case 2:printf("You choosed not to perform any conversions\n");
printf("Have a nice day!");
break;

default:printf("Wrong Choice!!");
break;
}
return 0;

}

mahimachoudhury
Автор

#include <stdio.h>

int main() {
int choice;
double value;

printf("Unit Conversion Menu:\n");
printf("1. Kilometers to Miles\n");
printf("2. Inches to Feet\n");
printf("3. Centimeters to Inches\n");
printf("4. Pounds to Kilograms\n");
printf("5. Inches to Meters\n");
printf("Enter your choice (1-5): ");
scanf("%d", &choice);

printf("Enter the value to convert: ");
scanf("%lf", &value);

switch (choice) {
case 1:
printf("%.2lf kilometers is equal to %.2lf miles.\n", value, value * 0.621371);
break;
case 2:
printf("%.2lf inches is equal to %.2lf feet.\n", value, value / 12);
break;
case 3:
printf("%.2lf centimeters is equal to %.2lf inches.\n", value, value * 0.393701);
break;
case 4:
printf("%.2lf pounds is equal to %.2lf kilograms.\n", value, value * 0.453592);
break;
case 5:
printf("%.2lf inches is equal to %.2lf meters.\n", value, value * 0.0254);
break;
default:
printf("Invalid choice! Please enter a number between 1 and 5.\n");
}

return 0;
}

Googler
Автор

Just like you taught to breaking work in segments to make it easy I used help of functions
***
I know that it is a bit to lengthy though


#include<stdio.h>
int pov()//kilometer to miles
{
int km;
printf("What is the kilometer value?\n");
scanf("%d", &km);
printf("The conversion of %d kilometer is %0.2f miles", km, (km*0.621));
return 0;
}
int jav() // inch to miles
{
int inch;
printf("What is the inch value?\n");
scanf("%d", &inch);
printf("The conversion of %d inches is %.2f foot", inch, (inch*0.0833));
return 0;
}
int may() //centimeter to inches
{
int cms;
printf("What is the centimeter value?\n");
scanf("%d", &cms);
printf("The conversion of %d centimeter is %.2f inches", cms,(cms*0.393));
return 0;
}
int bat() // pound to kilogram
{
int p;
printf("What is the pound value?\n");
scanf("%d", &p);
printf("The conversion of %d pound is %.2f kilogram", p, (p*0.453));
return 0;
}
int bet() // inch to meter
{
int inch;
printf("What is the inch value?\n");
scanf("%d", &inch);
printf("The conversion of %d inches is %.2f meter", inch, (inch*0.0254));
return 0;
}


int main()
{
int n;
printf("We have five type conversion only\n\n");
printf("1.kilometer to miles\n\n2.inch to miles\n\n3.centimeter to inches\n\n4.pound to kilogram\n\n5.inch to meter\n\n ");

printf("Enter the index No. for the conversion you want\n");

scanf("%d", &n);
if (n==1)
{
pov();
}
else if (n==2)
{
jav();
}
else if (n==3)
{
may();
}
else if (n==4)
{
bat();
}
else if (n==5)
{
bet();
}

return 0;
}

sc
Автор

#include <stdio.h>

int main()
{
int a ;
printf("Enter the mass in kg \n");
scanf ("%d", &a);
printf("You have entered mass %d Kg \n", a);
printf("Your converted mass in grams is %d\n", a*1000);
return 0;
}

rakeshroshan
Автор

Helpfull video Harry Bhai 👍🏻👍🏻 thank you..
Continue Harry Bhai, I will support you.

deepgrishsingh
Автор

Is exercise ko function se karna hai ki ya fir switch case use kare

tushargaming
Автор

challenge accepted sir. maza hi aa jayega

A.De
Автор

Challenges accepted 🤠
Thank you so much sir

pradeeppradeepkanaujiya
Автор

Your videos are very helpful...thanks a lot ...

pradeepchandra
Автор

Three years challenge accepted.
#include <stdio.h>
// KMS to miles
float ktm(float a)
{
printf("1 KMS = 0.621 MILES\n");
printf("Converting KILOMETERS to MILES\n");
printf("%f\n", a * 0.621);
}

// inches to foot
float itf(float a)
{
printf("1 INCH = 0.0833 FOOT\n");
printf("Converting INCHES to FOOT\n");
printf("%f\n", a * 0.0833);
}

// CENTIMETERS TO INCHES
float cti(float a)
{
printf("1 CENTIMETER = 0.394 INCHES\n");
printf("Converting CENTIMETERS to INCHES\n");
printf("%f\n", a * 0.394);
}

// POUNDS TO KGS
float ptk(float a)
{
printf("1 POUNDS = 0.454 KILOGRAM\n");
printf("Converting POUNDS to KILOGRAMS\n");
printf("%f\n", a * 0.454);
}

// MAIN MENU
char mainmenu()
{
char ch1;
float a;
printf("Enter the value to be converted\n");
scanf("%f", &a);
printf("1. KILOMETERS to MILES\n");
printf("2. INCHES to FOOT\n");
printf("3. CENTIMETERS to INCHES\n");
printf("4. POUNDS to KILOGRAM\n");
printf("Enter your choice no.:\n");
scanf("%d", &ch1);
if (ch1 == 1)
{
ktm(a); //calling
}
else if (ch1 == 2)
{
itf(a); //calling
}
else if (ch1 == 3)
{
cti(a); //calling
}
else if (ch1 == 4)
{
ptk(a); //calling
}
}
//SKELETON PROGRAM
int main()
{
char ch2;
float a;
int i = 1;
printf("WELCOME TO THE UNIT CONVERSION STATION\n");
//calling main menu
mainmenu();

while (i = 1)
{
printf("Do you want to convert more( Y/N ):\n");
scanf(" %c", &ch2);
if (ch2 == 'y' || ch2 == 'Y')
{
mainmenu();
}
else
{
printf("Thank you");
break;
}
}

return 0;
}

vanshikakaushik
Автор

#include <stdio.h>
float kmstomiles(float kms);//for kms to miles
float inchestofoot(float inch);//for inches to foot
float cmstoinches(float cms);//for cms to inches
float poundtokgs(float pound);//for pound to kgs
float inchtometer(float inch);//for inches to meters

int main()
{
int choose;
float kms, inch, cms, pound;
label:
printf("Which kind of conversion do you want to do\n");
printf("1..kms to miles\n");
printf("2..inches to foot\n");
printf("3..cms to inches\n");
printf("4..pound to kgs\n");
printf("5..inches to meters\n");
scanf("%d", &choose);
switch(choose)
{
case 1: //kms to miles
printf("You want to convert kms to miles\nEnter kms\n");
scanf("%f", &kms);
printf("%12.10f Miles in %f kms\n\n", kmstomiles(kms), kms);
break;

case 2://for inches ti foot
printf("You want to convert inches to foot\nEnter inches\n");
scanf("%f", &inch);
printf("%12.10f feet in %f inches\n\n", inchestofoot(inch), inch);
break;

case 3://for cms to inches
printf("You want to convert cms to inches \nEnter cms\n");
scanf("%f", &cms);
printf("%12.10f inches in %f cms\n\n", cmstoinches(cms), cms);
break;
case 4://for pound to kgs
printf("You want to convert pound to kgs \nEnter pound\n");
scanf("%f", &pound);
printf("%12.10f kgs in %f pounds\n\n", poundtokgs(pound), pound);
break;
case 5://for inches to meters
printf("You want to convert inches to meters \nEnter inches\n");
scanf("%f", &inch);
printf("%12.10f meters in %f inches\n\n", inchtometer(inch), inch);
break;
default:
printf("You entered wrong entry\nChoose the right

}
goto label;
return 0;
}

float kmstomiles(float kms)
{
float i;
i=(kms*0.62137);
return i;
}
float inchestofoot(float inch)
{
float i;

return i;
}
float cmstoinches(float cms)
{
float i;
i=(cms*0.393700787);
return i;

}
float poundtokgs(float pound)
{
float i;
i=(pound*0.45359237);
return i;

}
float inchtometer(float inch)
{
float i;
i=(inch*0.0254);
return i;

}

themultiply
Автор

Challenge accepted bro.
maine ise switch case se kiye, jra dekho bro.
#include <stdio.h>
float miles(float kms)
{
return kms * 0.621;
}
float feet(float inches)
{
return inches * 0.0833;
}
float inches(float cms)
{
return cms * 0.393701;
}
float kgs(float pound)
{
return pound * 0.453592;
}
float metres(float inches)
{
return inches * 0.0254;
}

int main()
{

int index;
float value;
printf(" \t\t\t\t Welcome to the CJ CONVERTER \n\n\n");
Converter:
printf(" Press 1 for converting Kms to Miles\n Press 2 for Converting Inches to Feet\n Press 3 for converting Cms to Inches\n Press 4 to convert Pound to Kgs\n Press 5 to convert Inches to Metres\n Press 0 to exit \n ");
scanf("%d", &index);
switch (index)
{
case 1:
printf("Enter the value in Kms \n ");
scanf("%f", &value);
printf("%f Kms = %f Miles\n\n", value, miles(value));
goto Converter;
case 2:
printf("Enter the value in Inches \n ");
scanf("%f", &value);
printf("%f Inches = %f Feet\n\n", value, feet(value));
goto Converter;
case 3:
printf("Enter the value in Cms \n ");
scanf("%f", &value);
printf("%f Cms = %f Inches\n\n", value, inches(value));
goto Converter;
case 4:
printf("Enter the value in Pound \n ");
scanf("%f", &value);
printf("%f Pound = %f Kgs\n\n", value, kgs(value));
goto Converter;
case 5:
printf("Enter the value in Inches \n ");
scanf("%f", &value);
printf("%f Inches = %f Metres\n\n", value, metres(value));
goto Converter;
case 0:
printf(" \t\t\t\t Thanks for using CJ CONVERTER");
break;

default:
printf(" \t\t\t\t Sorry invalid command\n \t\t\t\t Enter your command again\n\n\n\n ");
goto Converter;
}
return 0;
}

chiragjain