C Program printing Celsius-Fahrenheit table

Hi Friends!!

This is the 2nd Program of our Temperature Conversion Table.

This time we converted from Celsius to Fahrenheit using the formula

F = C *(9/5)+32

where

C is Celsius
F is Fahrenheit 

Here is the program

/*Program printing Celsius-Fahrenheit table*/

#include <stdio.h>

#include <conio.h>

#define LOWER 0 /* lower limit of table */

#define UPPER 200 /* upper limit */

#define STEP 10 /* step size */

 

int main()

{

     int celc;

     printf(” Celsius\t Fahrenheit\n\n “);

     for (celc = LOWER; celc <= UPPER; celc = celc + STEP)

     printf(” %d \t   %6.1f\n”, celc, celc *(9.0/5.0)+32);

    

     getch();

     return 0;   

}

Screenshot of the o/p

TemperatureTableCelsiusToFahrenheit


C Program printing Fahrenheit-Celsius table

Hi Friends!!

This is a C Program Printing Fahrenheit-Celsius table

Here we have converted from  Fahrenheit to Celsius using the formula

C = (5/9)*(F-32)

where

C is Celsius
F is Fahrenheit 


/*Program printing Fahrenheit-Celsius table*/

#include <stdio.h>

#include <conio.h>

#define LOWER 0 /* lower limit of table */

#define UPPER 200 /* upper limit */

#define STEP 10 /* step size */

 

int main()

{

    int fahr;

    printf(” Fahrenheit \t Celsius\n\n “);

    for (fahr = LOWER; fahr <= UPPER; fahr = fahr + STEP)

    printf(” %d \t   %6.1f\n”, fahr, (5.0/9.0)*(fahr-32));

 

    getch();

    return 0;  

}

Snapshot of the output

TemperatureTableInC

Factorial Function in C

Hi Friends

I hope you missed me. Here’s a C Program showing Factorial functionality.

/* Program demonstrating Factorial Function */

 

#include<stdio.h>

#include<conio.h>

 

//Factorial Function 1st version

int factorial1(int num)

{

      int i;

      int result = 1;

     

      for(i=1; i<=num; i++)

      {

               result = result * i;

      }

     

      return result; 

}

 

//Factorial Function 2nd version

int factorial2(int num)

{

      int i;

      int result = 1;

     

      for(i=num; i>=1; i–)

      {

               result = result * i;

      }

     

      return result; 

}

int main()

{

     int num = 3;

    

     printf(“\n ##Factorial Function in C## \n”);

    

     printf(“\n Factorial of %d is %d”, num, factorial1(num));

    

     printf(“\n Factorial of 5 is %d”, factorial2(5));

    

     getch();

     return 0;  

}

Snapshot of the o/p

FactorialC

Swap Function in C using Pointers

Hi Friends

This is the popular swap() function in C showing the working of Pointers as Function Arguments.


/* Program demonstrating Swap Function */

#include<stdio.h>

#include<conio.h>

 

//Swap Function in C

//pass by value

void swap(int num1, int num2)

{

     int num3;

     num3=num1;

     num1=num2;

     num2=num3; 

    

     printf(“\n Inside Swap Function \n”);

     printf(“\n num1 = %d”, num1);

     printf(“\n num2 = %d”, num2);

     printf(“\n”);

}

 

//pass by reference

void swapref(int *num1, int *num2)

{

     int num3;

     num3=*num1;

     *num1=*num2;

     *num2=num3;  

}

int main()

{

     int a, b, c;

     a=2;

     b=3;

    

     printf(“\n ~~~Swapping two Numbers in C~~~ \n”);

    

     printf(“\n Before Swapping \n”);

     

     printf(“\n a = %d”, a);

     printf(“\n b = %d”, b);

     printf(“\n”);

    

     swap(a,b);

     printf(“\n After Swapping in main (pass by value)\n”);

     printf(“\n a = %d”, a);

     printf(“\n b = %d”, b);

     printf(“\n”);

    

     printf(“\n After Swapping (pass by reference) \n”);

     swapref(&a,&b);

     

     printf(“\n a = %d”, a);

     printf(“\n b = %d”, b);

   

     getch();

     return 0;  

}

Snapshot of the o/p




Swapping Two Nos in C

A simple C Program swapping two numbers. Enjoy!!! ;) :D

Level- Very Beginner

/*  Program demonstrating Swapping two Numbers  */

#include<stdio.h>

#include<conio.h>

 

int main()

{

     int a, b, c;

     a=2;

     b=3;

     printf(“\n ~~~Swapping two Numbers in C~~~ \n”);

     printf(“\n Before Swapping \n”);

     

     printf(“\n a = %d”, a);

     printf(“\n b = %d”, b);

     printf(“\n”);

    

     c=a;

     a=b;

     b=c;

   

     printf(“\n After Swapping \n”);

     

     printf(“\n a = %d”, a);

     printf(“\n b = %d”, b);

     getch();

     return 0;  

}

Snapshot