Sunday, 21 June 2015

C program to find Factorial of a given Number.

To print a factorial of a number:

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

void main()
{
    int c, n; //Declaring Variable.
    unsigned long int fact=1;         
     
   
    printf("Enter an integer: "); //For printing
    scanf("%d",&n); //For Input.

    if ( n< 0)
        printf("Error!!! Factorial of negative number doesn't exist."); //For printing
    else
    {
       for(c=1;c<=n;++c)    //for loop 
          fact*=count;  
        
    printf("Factorial = %lu",fact); //For printing
    }

   getch(); //Getting a character or waiting for key press 
}

 
Output:



                        

C Program to Print a table of given number.

To print the table of given number.

Program:

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

 void main()
{
   int i,a,b;  
//Declaring Variable.

   

   printf("Enter the Table number"); //For printing
   scanf("%d",&a); //For Input.
   
   printf("Till where you want to print the table"); //For printing
   scanf("%d",&b);  //For Input.
   
  for(i=1;i<=b;i++)  //for loop
  printf("\n %d*%d = %d",a,i,a*i); 
//For printing


  getch();  //Getting a character or waiting for key press
}
Output:


C Program Swapping Number.

a)  With using third variable.
Program:

#include<stdio.h>
#include<conio.h>
 
void main()
{
   int x, y,temp;  //Declaring Variable.
  
 
   printf("Enter the value of x and y\n");  //For printing
   scanf("%d%d",&x,&y);  //For Input.
 
   printf("Before Swapping\nx = %d\ny = %d\n", x, y);  //For printing
   
   //performing Swap 
  temp=b;
  b=a;
  a= temp;
   
 
   printf("After Swapping\nx = %d\ny = %d\n", x, y);  //For printing
 
getch();  //Getting a character or waiting for key press
}
 
Output:


b) Without using third Variable
 Program:
#include<stdio.h>
#include<conio.h>
void main()
 {
   int a, b;  //Declaring Variable.
    
   
   printf("\nEnter value for num1 & num2 : ");  //For printing
   scanf("%d %d", &a, &b); //For Input.
    //performing Swap
   a = a + b;   
   b = a - b;
   a = a - b;
   printf("\nAfter swapping value of a : %d", a);  //For printing
   printf("\nAfter swapping value of b : %d", b);  //For printing
   getch();  //Getting a character or waiting for key press
}
Output:

Simple Calculator C program

Simple Calculator

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

void main()
{
    int a,b,c,d=0,e;  //Declaring Variable.
  
    
    while(d==0)
   { printf("Enter two Numbers");   //For printing
      scanf("%d %d",&a,&b);   //For Input.
      e=0;
    while(e==0)
     { printf("\n1- For Addition");  //For printing
        printf("\n2- For Multiplication");  //For printing
        printf("\n3- For Division");  //For printing
    printf("\n4- For Subtraction");//For printing
       printf("\n5- Reenter the Numbers"); //For printing
        printf("\n6- To exit");  //For printing
        printf("\n Enter the Choice");  //For printing
        scanf("%d",&c);   //For Input.   
        switch(c)
      {
        case 1:{
                        printf("\n Addition : %d",a+b);  //For printing
                        break;
                      }
        case 2:{
                        printf("\n Multiplication : %d", a*b);  //For printing
                        break;
                       }
        case 3:{
                      printf("\n Division : %d",a/b);  //For printing
                      break;
                     } 
        case 4:{
                      printf("\n Subtraction : %d", a-b);  //For printing
                      break;
                     }
        case 5:{e=1;
                      break;
                     }
        case 6: {e=1;
                       d=1;
                       break;
                      }
        default:{
                       printf("Error! operator is not correct");  //For printing
                       break;
                       }
      }
  }
}
    getch();  //Getting a character or waiting for key press
}

Output:


Friday, 19 June 2015

C Program to find greatest among four.

Program to find greatest among four numbers.
Program:

#include<stdio.h> 
#include<conio.h>
void main()
{
       float a,b,c,d,n; //Declaring Variable.

       

       printf("Enter the Four Numbers :");  //For printing
       scanf("%f %f %f %f",&a,&b,&c,&d);   //For Input.


         

       n=(a>b && a>c && a>d) ? a: ((b>c && b>d) ? b: ((c>d)?c:d)); 
     
       printf("Greatest Number is : %f",n);  //For printing


       getch();    //Getting a character or waiting for key press

}
Output:


Thursday, 18 June 2015

C program to find greatest among 3 numbers

To find the greatest among 3 numbers 

a)using if else statements.
 
Program:
 
#include <stdio.h>
#include<conio.h>

void main()
{
      float a, b, c;  //Declaring Variable.
      

      printf("Enter three numbers: ");  //For printing
      scanf("%f %f %f", &a, &b, &c);  //For Input.

      if (a>=b && a>=c)
            printf("Largest number = %.2f",a);  //For printing

      else if(b>=a && b>=c)
            printf("Largest number = %.2f",b);  //For printing
     
      else 
            printf("Largest Number = %.2f",c);   //For printing

      getch();  //Getting a character or waiting for key press
}
Output:

b)To find greatest among three numbers using &&.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
 int a,b,c,big;  //Declaring Variable.
printf("Enter the Three Numbers"); //For printing
scanf("%d%d%d",&a,&b,&c);  //For Input.
big=(a>b && a>c ? a:b>a && b>c ? b:c );
printf("Biggest Number = %d",big); //For printing
getch();   //Getting a character or waiting for key press
}
Output:

Tuesday, 16 June 2015

C Program to find greatest of two numbers

WAP for greatest among two numbers.
Program:
#include<stdio.h>
#include<conio.h>

int main()
{
 int a,b,c;    //Declaring Variable.


 printf("\n Enter two Numbers: ");  //For printing
 scanf("%d %d",&a,&b);    //For Input.

 c=(a>b)?a:b;

 printf("\n The Greatest number is : %d",c);  //For printing

 getch();  //Getting a character or waiting for key press.
 return 0;

}


Output:


Video Explanation
Sorry Guys Explanation of this tutorial will be posted later this month.

C program to check leap year.

WAP to check whether the year entered by the user is leap year or not.
Program:
#include<stdio.h>
#include<conio.h>
int main()
{
    int year;    //Declaring Variable.
   
    printf("Enter any year: ");  //For printing
    scanf("%d",&year);  //For Input.

    if(((year%4==0)&&(year%100!=0))||(year%400==0))  //If Statement
         printf("%d is a leap year",year);  //For printing
    else
         printf("%d is not a leap year",year);  //For printing
    getch(); //Getting a character or waiting for key press
 return 0;
}

Output:

Video Explanation
Sorry Guys Explanation of this tutorial will be posted later this month.