C programming Write a program that will read two floating point numbers (the fir
ID: 667770 • Letter: C
Question
C programming
Write a program that will read two floating point numbers (the first read into a variable called first and the second read into a variable called second) and then calls the function swap with the actual parameters first and second. The swap function having formal parameters number1 and number2 should swap the value of the two variables.
Sample Run:
Enter the first number
Then hit enter
80
Enter the second number
Then hit enter
70
You input the numbers as 80 and 70.
After swapping, the first number has the value of 70 which was the value of the second number
The second number has the value of 80 which was the value of the first number
Explanation / Answer
Swap Two Numbers / Variables using Pointer :
#include<stdio.h>
#include<conio.h>
{
void swap(int *num1, int *num2)
int temp;
temp = *num1;
*num1 = *num2;
*num2 = temp;
}
int main()
{
int num1, num2;
printf(" Enter the first number : ");
scanf("%d", &num1);
printf(" Enter the Second number : ");
scanf("%d", &num2);
swap(&num1, &num2);
printf(" First number : %d", num1);
printf(" Second number : %d", num2);
return (0);
}
Output :
Enter the first number : 12
Enter the Second number : 22
First number : 22
Second number : 12
Swaping two numbers using pointers:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.