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;
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
Post a Comment