Menu

Wednesday 2 March 2016

C program to swap two numbers

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

void main()
{
   int tval , a, b;

   printf("Enter the first value :\n");
   scanf("%d", &a);
   printf("Enter the second value :\n");
   scanf("%d", &b);

   printf("Before Swapping values are\n a = %d\n b= %d\n",a,b);

   tval = a;
   a    = b;
   b    = tval;

   printf("After Swapping\na = %d\nb = %d\n",a,b);

   getch();
}

Factorial Program in C

#include <stdio.h>
#include<conio.h>
void main()
{
  int numbr, fac = 1, k ;

  printf("Enter a number \n");
  scanf("%d", &numbr);

  for (k = 1; k <= numbr; k++)
{  
   fac = fac * k;
}
  printf("Factorial of %d is  %d\n", numbr, fac);

  getch();
}

C Program for Fibonacci Series

#include<stdio.h>
#include<conio.h>
void main()
{
   int num, a = 0, b = 1, t, c;

   printf("Enter the number of terms\n");
   scanf("%d",&num);

   printf("Fibonacci series upto first %d terms :-\n",num);

   for ( c = 0 ; c < num ; c++ )
   {
      if ( c <= 1 )
         t = c;
      else
      {
         t = a + b;
         a = b;
         b = t;
      }
      printf("%d\n",t);
   }

   getch();
}

C Program to use printf statement

#include<conio.h>
#include<stdio.h>
void main()
{
 printf("Hello Everyone"); // Here we are using printf statement
getch();
}