Swap of Two Numbers using Pointers : C Program

Computer Science » C Program » Swap of Two Numbers using Pointers 

Program :

#include <stdio.h>
 
int main()
{
    int x,y,temp,*a,*b;
 
    printf("Enter the two numbers : ");
    scanf("%d%d",&x,&y);
    
    printf("nBefore swapping : n x = %dn y = %dn",x,y);
 
    a = &x;
    b = &y;
 
    temp = *b;
    *b = *a;
    *a = temp;
 
    printf("After swapping : n x = %dn y = %dn",x,y);
   
    return 0;
}

Output :

Enter the two numbers : 
10
20
Before swapping : 
 x = 10
 y = 20
After swapping : 
 x = 20
 y = 10
Subject Name : Computer Science
Exam Name : IIT GATE, UPSC ESE, RRB, SSC, DMRC, NMRC, BSNL, DRDO, ISRO, BARC, NIELIT
Posts Name : Assistant Engineer, Management Trainee, Junior Engineer, Technical Assistant
Computer Science Books

GATE 2023 Total InfoENGG DIPLOMAUGC NET Total Info
IES 2023 Total InfoPSUs 2022 Total InfoCSIR UGC NET Total Info
JAM 2023 Total InfoM TECH 2023 Total InfoRAILWAY 2022 Total Info

Related Posts

  • Even Number Pyramid : C ProgramComputer Science » C Program » Even Number Pyramid Program : [php]#include&lt;stdio.h&gt; int main() { int i, j, num = 2; for (i = 0; i &lt; 4; i++) { num = 2; for (j = 0; j &lt;= i; j++) { printf(&quot;%dt&quot;, num); num = num + 2; } printf(&quot;n&quot;); } return (0); }[/php] Output : [php]2 2 4 2 4 6 2 4 6 8 [/php]
    Tags: program, computer, science, output, programs
  • Check Whether Two Numbers are Equal or Not : C ProgramComputer Science » C Program » Check Whether Two Numbers are Equal or Not Program : [php]#include <stdio.h> int main() { int num1, num2; printf("Enter the two integer numbers : "); scanf("%d %d", &num1, &num2); if (num1 == num2) printf("nThe two numbers are equal.n"); else printf("nThe two numbers are not equal.n"); }[/php] Output 1: [php]Enter the two integer numbers : 10 10 The two numbers are equal.[/php] Output 2: [php]Enter the two integer numbers : 10 11 The two numbers are not equal.[/php]
    Tags: program, numbers, output, computer, science, programs
  • Prime Number Pyramid : C ProgramComputer Science » C Program » Prime Number Pyramid Program : [php]#include<stdio.h> int prime(int num); int main() { int i, j; int num = 2; for (i = 0; i < 5; i++) { printf("n"); for (j = 0; j <= i; j++) { while (!prime(num)) { num++; } printf("%dt", num++); } } return (0); } int prime(int num) { int i, flag; for (i = 2; i < num; i++) { if (num % i != 0) flag = 1; else { flag = 0; break; } } if (flag == 1 || num == 2) return (1); else return (0); }[/php] Output : [php]2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 [/php]
    Tags: program, computer, science, output, programs
  • Rectangle using Line and Special Symbols : C ProgramComputer Science » C Program » Rectangle using Line and Special Symbols Program : [php]#include<stdio.h> int main() { int i, j; for (i = 0; i < 10; i++) { printf("n"); for (j = 0; j < 10; j++) { if (i == 0 || i == 9 || j == 0 || j == 9) printf("▲"); else printf("-"); } } return (0); }[/php] Output : [php]▲▲▲▲▲▲▲▲▲▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲▲▲▲▲▲▲▲▲▲[/php]
    Tags: program, computer, science, output, programs
  • Pyramid of Multiplication Tables : C ProgramComputer Science » C Program » Pyramid of Multiplication Tables Program : [php]#include<stdio.h> int main() { int i, j; for (i = 0; i <= 6; i++) { for (j = 0; j <= i; j++) { printf("%dt", i * j); } printf("n"); } return(0); }[/php] Output : [php]0 0 1 0 2 4 0 3 6 9 0 4 8 12 16 0 5 10 15 20 25 0 6 12 18 24 30 36 [/php]
    Tags: program, computer, science, output, programs

LEAVE A REPLY

Please enter your comment!
Please enter your name here