1.
CODE FOE ADDITION
#include<stdio.h>
int main(){
int x,y;
printf("enter the vallue of x and y;");
scanf("%d%d",&x,&y);
printf("addition %d + %d = %d\n",x,y,x+y);
printf("subtraction %d - %d = %d\n",x,y,x-y);
printf("quotient %d / %d = %d\n",x,y,x/y);
printf("reminder %d & %d = %d\n",x,y,x%y);
return 0;
2. Write a menu driven program that allow the user to perform any
one of the following operations based on the input given by user:
a. check number is even or odd
b. check number is positive or negative
c. printing square of the number
d. printing square root of the number
Note: Use switch statement & Refer goto for repeat execution of the
code.
#include <stdio.h>
#include <math.h> // Include math.h for sqrt function
int main() {
int choice, num;
double result;
// Label for repeating the program
start:
// Displaying the menu
printf("\n--- Menu ---\n");
printf("1. Check if number is even or odd\n");
printf("2. Check if number is positive or negative\n");
printf("3. Print square of the number\n");
printf("4. Print square root of the number\n");
printf("Enter your choice (1-4): ");
scanf("%d", &choice);
// Asking the user to input a number
printf("Enter a number: ");
scanf("%d", &num);
// Switch statement for different operations
switch(choice) {
case 1:
// Check if the number is even or odd
if (num % 2 == 0)
printf("%d is an even number.\n", num);
else
printf("%d is an odd number.\n", num);
break;
case 2:
// Check if the number is positive or negative
if (num > 0)
printf("%d is a positive number.\n", num);
else if (num < 0)
printf("%d is a negative number.\n", num);
else
printf("The number is zero.\n");
break;
case 3:
// Calculate and print the square of the number
printf("The square of %d is %d.\n", num, num * num);
break;
case 4:
// Calculate and print the square root of the number
if (num >= 0) {
printf("The square root of %d is %.2f.\n", num,sqrt(num));
} else {
printf("Square root of a negative number is not real.\n");
break;
default:
// Invalid choice
printf("Invalid choice! Please select from 1 to 4.\n");
return 0;