Swap Two Numbers in C

  Swap Two Numbers in C In this example, you will learn to swap two numbers in C programming using two different techniques. To understand this example, you should have the knowledge of the following C programming topics: C Data Types C Programming Operators C Input Output (I/O) Swap Numbers Using Temporary Variable # include <stdio.h> int main () { double first, second, temp; printf ( "Enter first number: " ); scanf ( "%lf" , &first); printf ( "Enter second number: " ); scanf ( "%lf" , &second); // Value of first is assigned to temp temp = first; // Value of second is assigned to first first = second; // Value of temp (initial value of first) is assigned to second second = temp; printf ( "\nAfter swapping, firstNumber = %.2lf\n" , first); printf ( "After swapping, secondNumber = %.2lf" , second); return 0 ; } Output ...

3D array print using three nested loops.c

3D array print using three nested loops in c :

#include<stdio.h>

int main()

{

 int i,j,k;

 int a[2][2][3] = { {{1,2,3}, {4,5,6}},

{{7,8,9}, {10,11,12}} };

    {

     for(i = 0; i < 2; i++)

     {

      for(j = 0; j < 2; j++)

      {

       for(k = 0; k < 3; k++)

       printf("%d ",a[i][j][k]);

      }

     }

    }

 return 0;

}

 

Code in Terminal :

















Output :



Comments

Popular posts from this blog

Find GCD of two Numbers in C

Swap Two Numbers in C