0% found this document useful (0 votes)
4 views2 pages

Name-Shreyas Manish Chaudhari ROLL NO-110057 Div - 10 Batch-J3

The document contains a lab assignment for swapping two numbers in C programming. It provides two methods: one without using pointers and another using pointers, including the code and expected output for both methods. The output demonstrates the successful swapping of the numbers in each case.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Name-Shreyas Manish Chaudhari ROLL NO-110057 Div - 10 Batch-J3

The document contains a lab assignment for swapping two numbers in C programming. It provides two methods: one without using pointers and another using pointers, including the code and expected output for both methods. The output demonstrates the successful swapping of the numbers in each case.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

NAME-SHREYAS MANISH CHAUDHARI

ROLL NO- 110057


DIV- 10 BATCH-J3

LAB ASSIGNMENT

Q : Swap two numbers without using pointer

#include<stdio.h>
int main()
{
int a,b,c;
printf("\nEnter two numbers=");
scanf("%d%d",&a,&b);
printf("\nBefore Swap:");
printf("\na=%d\nb=%d",a,b);
c=a;
a=b;
b=c;
printf("\nAfter Swap:");
printf("\na=%d\nb=%d",a,b);
return 0;
}

OUTPUT
Enter two numbers=30
50

Before Swap:
a=30
b=50
After Swap:
a=50
b=30

Q : Swap two numbers using pointer?

#include<stdio.h>
int main()
{
int a,b,c;
int *p,*q;
p=&a;
q=&b;
printf("\nEnter two numbers=");
scanf("%d%d",&a,&b);
printf("\nBefore Swap:");
printf("\na=%d\nb=%d",a,b);
c=*p;
*p=*q;
*q=c;
printf("\nAfter Swap:");
printf("\na=%d\nb=%d",a,b);
return 0;
}

OUTPUT
Enter two numbers=50
30

Before Swap:
a=50
b=30
After Swap:
a=30
b=50

You might also like