0% found this document useful (0 votes)
45 views

A Program To Swap Two Numbers in C Language

This C program uses a third variable to swap the values of two input numbers. It prompts the user to enter two integer values, stores them in variables x and y, assigns x's value to a third variable z, assigns y's value to x, then assigns z's original value (which is now x's original value) to y, effectively swapping the values stored in x and y. It then prints the swapped values of x and y.

Uploaded by

Avi Manyu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

A Program To Swap Two Numbers in C Language

This C program uses a third variable to swap the values of two input numbers. It prompts the user to enter two integer values, stores them in variables x and y, assigns x's value to a third variable z, assigns y's value to x, then assigns z's original value (which is now x's original value) to y, effectively swapping the values stored in x and y. It then prints the swapped values of x and y.

Uploaded by

Avi Manyu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

A program to swap two numbers in C language

using third variable

#include <stdio.h>

int main()

int x,y,z;

printf(“Enter two values: “);

scanf(“%d%d”,&x,&y);

z=x;

x=y;

y=z;

printf(“x=%d and y=%d”,x,y);

Visit Sikshapath.in to explore more answers

You might also like