Wednesday, January 23, 2019

C Program To Swap Two Numbers Using Third Variable


Swap Two Numbers Using Third Variable:-
In this c program we swap two numbers by using a third variable. Here we take three int type of variable, name as num1, num2, num3. num1 and num2 variable for store first number and second number likewise and third used for interchanging the value when swapping. 
   /*
      Program : Swap Two Numbers Using Third Variable
      Filename : swapThirdVariable.c
      IDE Used To Developed : CodeBlocks
      Developed By : Pavito Golui
   */
  #include<stdio.h>
  int main()
   {
      int num1, num2,num3;
       printf("Enter the first number :");
       scanf("%d",&num1); 
       printf("Enter the second number :");
       scanf("%d",&num2); 
       printf("\nBefore swapping first no :%d\n",num1); 
       printf("Before swapping second no :%d\n\n",num2);
          num3=num1;
          num1=num2;
          num2=num3;
       printf("After Swapping First No :%d\n",num1); 
       printf("After Swapping Second No :%d\n",num2); 
      return 0;
    }
 

Output :

  Enter the first number : 11
  Enter the first number : 27
  
  Before swapping first no. : 11
  Before swapping second no. : 27
  
  Before swapping first no. : 27
  Before swapping second no. : 11

C Program To Print N Natural Numbers By User Input


Print N Natural Numbers:-
In this c program we will print N natural numbers by input values from user. Here we take two int type of variables name as num, i. num for store user input as last number and i variable for counter, i initialize with value 1 and iterate until the given condition become false i<=num.

   /*
      Program : N Natural Numbers
      Filename : nNaturalNumber.c
      IDE Used To Developed : CodeBlocks
      Developed By : Pavito Golui
   */
  #include<stdio.h>
  int main()
   {
      int num,i;
       printf("Enter the last number :");
       scanf("%d",&num); 
       for(i=1;i<=num;i++)
         {
             printf("%d \n",i);
         }
       return 0;
    }
 

Output :

  Enter the last number :15
  1
  2
  3
  4
  5
  6
  7
  8
  9
  10
  11
  12
  13
  14
  15

Sunday, January 20, 2019

C Program To Print First 10 Natural Numbers In Reverse Order


Print 10 Natural Numbers In reverse order:-
In this c program we will print first 10 natural numbers in reverse order by using for loop. Here we take a int type variable, name as num for counter. We initialize with 10 and decrement the value of num, break loop when reached 1 by giving condition num>=1.

   /*
      Program : 10 Natural Numbers In Reverse Order
      Filename : naturalNumberReverse.c
      IDE Used To Developed : CodeBlocks
      Developed By : Pavito Golui
   */
  #include<stdio.h>
  int main()
   {
      int num;
       for(num=10;num>=1;num--)
         {
             printf("%d \n",num);
         }
       return 0;
    }
 

Output :

  10
  9
  8
  7
  6
  5
  4
  3
  2
  1

C Program To Print First 10 Natural Numbers


Print 10 Natural Numbers:-
In this c program we will print first 10 natural numbers by using for loop. Here we take a int type variable, name as num for counter. We initialize with 1 and increment the value of num,  break loop when reached 10 by giving condition num<=10.

   /*
      Program : 10 Natural Numbers
      Filename : naturalNumber.c
      IDE Used To Developed : CodeBlocks
      Developed By : Pavito Golui
   */
  #include<stdio.h>
  int main()
   {
      int num;
       for(num=1;num<=10;num++)
         {
             printf("%d \n",num);
         }
       return 0;
    }
 

Output :

  1
  2
  3
  4
  5
  6
  7
  8
  9
  10

Thursday, January 17, 2019

C Program To Print Greatest Number Among Three Numbers


Greatest number among three numbers:-

In this C program we will print greatest one number among three numbers from user input value. Here we take three int type variables, name as num1, num2, num3  for input first ,second and third number.

   /*
      Program : Greatest Number Among  Three Numbers
      Filename : greatestNumberThree.c
      IDE Used To Developed : CodeBlocks
      Developed By : Pavito Golui
   */
  #include<stdio.h>
  int main()
   {
       int num1,num2,num3;
       printf("Enter the first number :");
       scanf("%d",&num1);
       printf("Enter the second number :");
       scanf("%d",&num2);
       printf("Enter the third number :");                       
       scanf("%d",&num3);
          if(num1>num2 && num1>num3)
             {
                  printf("First number is greater than second and third number");
             }
           else if(num2>num3)
             {               
                  printf("Second number is greater than first and third number");
            
           else
             {
                printf("Third number is greater than first and second number");
             }  
       return 0;
   } 

Output :

  Program run first time:-
 
  Enter the first number :7
  Enter the second number :16
  Enter the second number :18
  Third number is greater than first and  second number
 
  Program run second time:-
 
  Enter the first number :30
  Enter the second number :20
  Enter the second number :15
  First number is greater than second and third number





C Program To Print Greater Number Between Two Numbers


Greater number between two numbers:-

In this C program we will print greater one number between two numbers from user input value. Here we take two int type variables for input first number and second number.

   /*
      Program : Greatest Numbers Between Two Numbers
      Filename : greatestNumber.c
      IDE Used To Developed : CodeBlocks
      Developed By : Pavito Golui
   */
  #include<stdio.h>
  int main()
   {
       int number1, number2;
       printf("Enter the first number :");
       scanf("%d",&number1);
       printf("Enter the second number :");
        scanf("%d",&number2); 
          if(number1>number2)
             {
                  printf("First number is greater than second number");            
             }
           else
             {               
                  printf("Second number is greater than first number");
             }  
       return 0;
   } 

Output :

  Program run first time:-
 
  Enter the first number : 18
  Enter the second number :12
  First number is greater than second number
 
  Program run second time:-
 
  Enter the first number : 156
  Enter the second number :174
  Second number is greater than first number