Showing posts with label Conversions. Show all posts
Showing posts with label Conversions. Show all posts

C Program To Convert Decimal To Binary Using Recursion

How to write a C Program To Convert Decimal To Binary Using Recursion in C Programming Language ?

Solution For C Program :

/*C Program To Convert Decimal To Binary Using Recursion*/

#include<stdio.h>
void main()
{
void dectobin(int);
int n;
printf("\nEnter Any Decimal Number : ");
scanf("%d", &n);
dectobin(n);
}
void dectobin(int a)
{
int d;
d = a % 2;
if(a != 0)
{
dectobin(a / 2);
printf("%d", d);
}
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Program To Convert Temperature In Celsius To Fahrenheit, Using Function

How to write a C Program/Code To Convert Temperature In Celsius To Fahrenheit, Using Function in C Programming Language ?


Solution For C Program : 

/*C Program To Convert Temperature In Celsius To Fahrenheit, Using Function*/

#include <stdio.h>
void main()
{
void Fahrenheit(float c);
float c;
printf("\nEnter the Temperature in Celsius : ");
scanf("%f", &c);
Fahrenheit(c);
}
void Fahrenheit(float c)
{
printf("\nThe Temperature %0.2f Celsius = %0.2f Fahrenheit.", c, ( 9 * c) / 5 + 32);
return;
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Program To Convert Temperature Into Celsius

How to write a C Program to convert given Temperature in Fahrenheit to Celsius, using Function in C Programming Language ?

Solution For C Program :

/*C Program To Convert Temperature Into Celsius*/

# include <stdio.h>
void main()
{
float f;
float Celsius(float f);
printf("\nEnter the Temperature in Fahrenheit : ");
scanf("%f", &f);
printf("\nThe %0.2f Fahrenheit = %0.2f Celsius.", f, Celsius(f));
}
float Celsius(float f)
{
return(5 * (f - 32) / 9);
}

You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Program Decimal to Binary Conversion

How to write a C Program Decimal to Binary Conversion in C Programming Language ?

Solution:

C Program Decimal to Binary Conversion

#include <stdio.h>

main()
{
   int n, c, k;

   printf("Enter an integer in decimal number system\n");
   scanf("%d",&n);

   printf("%d in binary number system is:\n", n);

   for ( c = 31 ; c >= 0 ; c-- )
   {
      k = n >> c;

      if ( k & 1 )
         printf("1");
      else
         printf("0");
   }

   printf("\n");

   return 0;
}

Simple Conversion Program in C

How to write a Simple Conversion Program in C Programming Language ?

This is Simple Conversion Program in C Programming.


1. Temperature converter
2. Distance converter


Temperature conversion list


1. Convert Celsius to Fahrenheit 
2. Convert Fahrenheit to Celsius

Output: What is the degrees in Celsius?
Output: What is the degrees in Fahrenheit?

Distance conversion list

1. Convert Inches to Centimetres
2. Convert Centimetres to Inches
3. Convert Feet to Meters
4. Convert Meters to Feet

Output: What is the distance in Inches?
Output: What is the distance in Centimetres?
Output: What is the distance in feet?
Output: What is the distance in meters?


Solution:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. /* README
  4.     A simple conversion program
  5.     Coded by SmakGezgo
  6. */
  7. int main()
  8. {
  9.     // Main program select
  10.     int list;
  11.     int con;
  12.     printf("Select a list:\n 1. Temperature converter\n 2. Distance converter\n");
  13.     scanf( "%d", &list);
  14.     // Temperature conversion list
  15.     if(list == 1){
  16.         printf("Select a converter:\n 1. Celsius to Fahrenheit\n 2. Fahrenheit to Celsius\n");
  17.         scanf( "%d", &con);
  18.     // Fahrenhiet to Celsius
  19.         if(con == 1){
  20.             int cel;
  21.             printf("What is the degrees in Celsius? \n");
  22.             scanf("%d", &cel);
  23.         int fah = (cel * 1.8) + 32;
  24.         printf("%d degrees Celsius is equal to %d degrees Fahrenheit. \n", cel, fah);
  25.         }
  26.     // Celsius to Fahrenhiet
  27.         else if(con == 2){
  28.             int fah;
  29.             printf("What is the degrees in Fahrenheit? \n");
  30.             scanf("%d", &fah);
  31.         int cel = (fah - 32) * .5556;
  32.         printf("%d degrees Fahrenheit is equal to %d degrees Celsius. \n", fah, cel);
  33.         }
  34.     }
  35.     // Distance conversion list
  36.     if(list == 2){
  37.         printf("Select a converter:\n 1. Inches to Centimetres\n 2. Centimetres to Inches\n 3. Feet to Meters\n 4. Meters to Feet\n");
  38.         scanf( "%d", &con);
  39.     // Inches to Centimeters
  40.         if(con == 1){
  41.             float in;
  42.             printf("What is the distance in Inches? \n");
  43.             scanf("%f", &in);
  44.         float cm = (in * .39);
  45.         printf("%.2f Inches is equal to %.2f Centimetres. \n", in, cm);
  46.         }
  47.     // Centimeters to Inches
  48.         if(con == 2){
  49.             float cm;
  50.             printf("What is the distance in Centimetres? \n");
  51.             scanf("%f", &cm);
  52.         float in = (cm * 2.54);
  53.         printf("%.2f Centimetres is equal to %.2f Inches. \n", cm, in);
  54.         }
  55.     // Feet to Meters
  56.         if(con == 3){
  57.             float ft;
  58.             printf("What is the distance in feet? \n");
  59.             scanf("%f", &ft);
  60.         float m = (ft / 3.2808);
  61.         printf("%.2f feet is equal to %.2f meters. \n", ft, m);
  62.         }
  63.     // Meters to Feet
  64.         if(con == 4){
  65.             float m;
  66.             printf("What is the distance in meters? \n");
  67.             scanf("%f", &m);
  68.         float ft = (* 3.2808);
  69.         printf("%.2f meters is equal to %.2f feet. \n", m, ft);
  70.         }
  71.     }
  72.     return 0;
  73. }