Q:

Write a C Program to Swap Two Numbers

0

Write a C Program to Swap Two Numbers using a temporary variable.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>

int main()
{
    
    int n1=10;
    int n2=5;
    printf("before swapping\n-----------------------------\n");
    printf("number1: %d\n",n1);
    printf("number2: %d\n",n2);
    
    int temp=n1;
    n1=n2;
    n2=temp;
    printf("after swapping\n-----------------------------\n");
    printf("number1: %d\n",n1);
    printf("number2: %d\n",n2);
    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now