P02: PROGRAM TO PRINT SUM OF TWO FUNCTIONS USING FUNCTIONS
#include <stdio.h> // Function Definition void add() { int i,j; printf("Enter 2 Numbers\n"); scanf("%d%d",&i,&j); printf("The sum of %d and %d is %d.",i,j,i+j); } void sub() { int i,j; printf("Enter 2 Numbers\n"); scanf("%d%d",&i,&j); printf("The sum of %d and %d is %d.",i,j,i-j); } void mul() { int i,j; printf("Enter 2 Numbers\n"); scanf("%d%d",&i,&j); printf("The sum of %d and %d is %d.",i,j,i*j); } int main() { int i; printf("Enter \nOption 1: Addition\nOption 2: Subtraction\nOption 3: Multiplication\n"); scanf("%d",&i); switch(i) { case 1: add();break; case 2: sub();break; case 3: mul();break; } return 0; }
P03: PROGRAM TO DO OPERATION ON TWO NUMBERS USING FUNCTIONS
#include <stdio.h> // Function Definition // Parameters : i,j int add(int i, int j) { // Return Variable return (i+j); } int sub(int i, int j) { return (i-j); } int mul(int i, int j) { return (i*j); } int division(int i, int j) { return (i/j); } int main() { int a,b,o,r; printf("Enter Two Numbers:\n"); scanf("%d%d",&a,&b); printf("Enter \nOption 1: Addition\nOption 2: Subtraction\nOption 3: Multiplication\nOption 4: Division\n"); scanf("%d",&o); switch(o) { case 1: r=add(a,b); printf("Sum of %d and %d = %d",a,b,r); break; case 2: r=sub(a,b);
printf("Difference of %d and %d = %d",a,b,r); break; case 3: r=mul(a,b); printf("Multiplication of %d and %d = %d",a,b,r); break; case 4: r=division(a,b); printf("Division of %d and %d = %d",a,b,r); break; default: printf("Invalid Option."); } return 0; }