-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMP-2Q6.c
More file actions
28 lines (25 loc) · 687 Bytes
/
MP-2Q6.c
File metadata and controls
28 lines (25 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* Program: MP-2,Q6
Write a program to swap two numbers using pointer with structure.
*/
#include <stdio.h>
struct rajkishor
{
int a;
int b;
} rk;
int main()
{
int t;
struct rajkishor *ptr = &rk;
printf("Enter the value of a and b : ");
scanf("%d%d", &(*ptr).a, &(*ptr).b);
printf("_____Before swaping values_____\n");
printf("\ta= %d\tb= %d", (*ptr).a, (*ptr).b);
// swap two number
t = (*ptr).a;
(*ptr).a = (*ptr).b;
(*ptr).b = t;
printf("\n_____After swaping values_____\n");
printf("\ta= %d\tb= %d", (*ptr).a, (*ptr).b);
return 0;
}