0% found this document useful (0 votes)
12 views6 pages

IT22111 Record - 96 (Ex9)

fuck you

Uploaded by

2024cs0502
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)
12 views6 pages

IT22111 Record - 96 (Ex9)

fuck you

Uploaded by

2024cs0502
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/ 6

IT22111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

EX.NO: 9.1
DATE:

PROGRAMS TO ILLUSTRATE POINTERS

QUESTION:

Demonstrate address of (*) and indirection (*) operators. Write a C program, to swap two
number using pointers.

AIM:
To write a C program to swap two numbers using pointers.

PSEUDO CODE:

Roll Number : 2127240801096 Page No. :


SOURCE CODE:

#include<stdio.h>
int swapping(int*,int*);
int main()
{
int x,y;
printf("Enter value of x:");
scanf("%d",&x);
printf("Enter value of y:");
scanf("%d",&y);
printf("\nx & y before swapping %d & %d", x, y);

swapping(&x,&y);
printf("\nx & y after swapping %d & %d\n", x, y);
return 0;
}

int swapping(int *a,int *b)


{
int x;
x=*a;
*a=*b;
*b=x;
return *a,*b;
}

SAMPLE OUTPUT:

RESULT:

The C program swaps two numbers using pointers and displays them successfully.

Roll Number : 2127240801096 Page No. :


IT22111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

EX.NO: 9.2
DATE:

PROGRAMS TO ILLUSTRATE POINTERS

QUESTION:

Implement a Pocket calculator with arithmetic operators (include increment/decrement


also).

AIM:

To write a C program for a pocket calculator with arithmetic operators using pointers.

PSEUDO CODE:

Roll Number : 2127240801096 Page No. :


SOURCE CODE:

#include<stdio.h>
int add(int*a,int*b)
{
return *a + *b;
}
int sub(int*a,int*b)
{
return *a - *b;
}
int multi(int*a,int*b)
{
return *a * *b;
}
int div(int*a,int*b)
{

Roll Number : 2127240801096 Page No. :


if(*b!=0)
{
return *a / *b;
}
else
{
printf("\nError!Division by zero.");
}
}
int modulo(int*a,int*b)
{
if(*b!=0)
{
return *a % *b;
}
else
{
printf("\nError!Division by zero.");
}
}
int inc(int*a)
{
printf("a:%d\n",*a);
return *a+1;
}
int dec(int *b)
{
printf("b:%d\n",*b);
return *b-1;
}

int main()
{
int a,b,ch;
printf("Enter the first number:");
scanf("%d",&a);
printf("Enter the second number:");
scanf("%d",&b);
printf("--calculator operation--");

printf("\n1.Addion\n2.Subtraction\n3.Multiplication\n4.Division\n5.Modulus\n6.Increment\
n7.Decrement");
printf("\nEnter your choice:");
scanf("%d",&ch);
switch (ch)
{
case 1:

Roll Number : 2127240801096 Page No. :


printf("Sum:%d",add(&a,&b));
break;
case 2: printf("Difference:
%d",sub(&a,&b)); break;
case 3: printf("Product:
%d",multi(&a,&b)); break;
case 4: printf("Division:
%d",div(&a,&b)); break;
case 5: printf("Modulo:
%d",modulo(&a,&b)); break;
case 6: printf("Increment:
%d",inc(&a)); break;
case 7: printf("Decrement:
%d",dec(&b)); break;
default:
printf("Enter a valid number");
}
printf("\n");
return 0;
}

SAMPLE OUTPUT:

RESULT:

The C program implements a pocket calculator with arithmetic operators using pointers
and displays the answer successfully.

Roll Number : 2127240801096 Page No. :

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy