C Programs:Introduction

 1.Write a c program to swap two numbers.

#include<stdio.h>

main() {

      int first, second, temp;

      printf("Enter first number: ");

      scanf("%d", &first);

      printf("Enter second number: ");

      scanf("%d", &second);

 

      // keeping the value of first in temp

      temp = first;

 

      // keeping the value of second in first

      first = second;

       second = temp;

      printf("\nAfter swapping, firstNumber = %d\n", first);

      printf("After swapping, secondNumber = %d", second);

    

}

 

Output

Enter first number: 5

Enter second number: 6

 

After swapping, first Number = 6

After swapping second Number=5


Comments

Popular Posts