GTU PPS Practical-4
Question :
Write a C program to interchange two numbers.
Logic :
In this program we have to change two numbers with eachother.
To change two numbers with each other we have one temporary variable which can store the value of any one.
Firstly, we take two numbers from user then we store 1st num in temporary variable.. thereafter store 2nd number into 1st number...then change 2nd number with temporary variable.
Let's look at the algorithm.
Algorithm:
- ‌START
- ‌Take two numbers
- ‌Compute temp = num1 , num1 = num2 , num2 = temp
- ‌Print a and b
- ‌STOP
Code :
#include<stdio.h> int main() { int num1,num2,temp; printf("\n Enter first number:"); scanf("%d",&num1); printf("\n Enter second number:"); scanf("%d",&num2); temp=num1; num1=num2; num2=temp; printf("\n interchanged numbers \n Your first number is %d \n your second number is %d", num1,num2); return 0; }
Output :
Here you can see output screen of the code. You can get this type of output if you write above code.
0 Comments
Donot make a spam in comment box.