AIM:To write a program for swapping of two numbers.
ALGORITHM:
Step1: Start the program.
Step2: Get the inputs a and b.
Step3: Find a=a+b.
Step4: Find b=a-b.
Step 5: Find a=a-b.
Step6: Print the result „a‟ and „b‟.
Step7: Stop the program.
PROGRAM:
#include<stdio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the values of a and b: ");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("The values of a and b are: %d %d", a, b);
}
Output
Enter the values of a and b: 10 20
The values of a and b are: 20 10
RESULT:
Thus the C program to swap two numbers has been successfully executed and verified.
No comments:
Post a Comment