Sunday, 24 April 2022

2. Write a user defined function calc(), which will returns the sum, subtraction, multiplication, and division values of two variable locally declared in the main function.

 



#include<stdio.h>
#include<conio.h>

void calc(int *,int *);

void main()
{
    int no1,no2;
    clrscr();

    printf("enter 1st number: ");
    scanf("%d",&no1);

    printf("enter 2nd number: ");
    scanf("%d",&no2);

    calc(&no1, &no2);

    getch();

}

void calc(int *a, int *b)
{
    printf("\n\naddition : %d",*a + *b);
    printf("\nsubtraction: %d",*a - *b);
    printf("\nmultiplication: %d",*a * *b);
    printf("\ndivision: %d",*a / *b);

}

/*  output:

enter 1st number: 10
enter 2nd number: 5


addition : 15
subtraction: 5
multiplication: 50
division: 2

*/

No comments:

Post a Comment

python programs

1. sum of two number