Simple C program to Print hello world



  • First program in c programming

#include<stdio.h>
#include<conio.h>

void main()
{
      clrscr();
      printf("HELLO WORLD");
      getch();
}

Output:

HELLO WORLD

Interchange or swapping of two variable's without third variable


  • TO INTERCHANGE THE VALUE WITHOUT WITHOUT THIRD VARIABLE

#include<stdio.h>
#include<conio.h>

void main()
{
      int a,b;
      clrscr();
      printf("Enter value of A and B : ");
      scanf("%d %d",&a,&b);
      a=a+b;
      b=a-b;
      a=a-b;
     printf("Value after interchangge are :");
     printf("\nA = %d\nB = %d",a,b);
     getch();
}

Output:

Enter value of A and B : 10 20
Value after interchange are:
A = 20
B = 10

TO INTERCHANGE THE VALUE WITHOUT USING THIRD VARIABLE


  • TO INTERCHANGE THE VALUE USING THIRD VARIABLE
#include<stdio.h>
#include<conio.h>

void main()
{
      int a,b,c;
      clrscr();
      printf("Enter value of A and B : ");
      scanf("%d %d",&a,&b);
      c=a;
      a=b;
      b=c;
     printf("Value after interchangge are :");
     printf("\nA = %d\nB = %d",a,b);
     getch();
}

Output:

Enter value of A and B : 10 20
Value after interchange are:
A = 20
B = 10

Addition of two number


  • FIND THE ADDITION OF TWO VARIABLES


#include<stdio.h>
#include<conio.h>

void main()
{
         float a,b,c;
         clrscr();
         printf("Enter the first number:");
         scanf("%f",&a);

         printf("Enter the second number:");
         scanf("%f",&b);

         c=a+b;

         printf("Your Answer is:%f",c);
         getch();
}


OUTPUT
Enter the first number:10
Enter the second number:20
Your Answer is:30

TO CONVERT THE GIVEN TEMPERATURE IN CELSIUS TO FAHRENHEIT

  • TO CONVERT THE GIVEN TEMPERATURE IN CELSIUS TO FAHRENHEIT

#include<stdio.h>
#include<conio.h>

void main()
{
          float f,c;
          clrscr();
          printf("Enter the temperature in Celsius:");
          scanf("%f",&c);

          f=(c*1.8)+32;

          printf("fehranhit is:%f",&f);
          getch();
}

Convert temperature in Fahrenheit to Celsius


  • TO CONVERT THE GIVEN TEMPERATURE IN FAHRENHEIT TO CELSIUS 


#include<stdio.h>
#include<conio.h>

void main()
{
          float f,c;
          clrscr();
          printf("Enter the fahrenheit:");
          scanf("%f",&f);

          c=(f-32)/1.8;

          printf("Celcius is:%f",&c);
          getch();
}

Find number is odd or even


  • TO FIND ODD OR EVEN FROM GIVEN NUMBER


#include<stdio.h>
#include<conio.h>

void main()
{
         int a;
         clrscr();
         printf("Enter the number:");
         scanf("%d",&a);

         if(a%2==0)
         {
                  printf("\n Number is even");
         }
         else
         {
                   printf("\n Number is Odd");
          }
          getch();
}

Output: 

Enter the number:5
Number is Odd