/*A menu program to check if the given number is odd or even, to find the sum of N natural numbers and to find the sum of squares of two numbers*/
#include<stdio.h>
#include<stdlib.h>
void main() {
int ch;
char y;
int n, a, sum = 0;
while (1) {
printf("\nMENU");
printf("\n1.To check if the given no is odd or even");
printf("\n2.To find the sum of N numbers");
printf("\n3.To find the sum of squares of two numbers");
printf("\n4.Exit from Program");
printf("\nEnter the choice: ");
scanf("%d", &ch);
switch (ch) {
case 1:
printf("\nEnter the no. ");
scanf("%d", &n);
if ((n % 2) == 0)
printf("\nIt is even");
else
printf("\nIt is odd");
break;
case 2:
printf("\nEnter the value of N: ");
scanf("%d", &n);
for (a = 1; a <= n; a++)
sum = sum + a;
printf("\nSum= %d", sum);
break;
case 3:
printf("\nEnter the two numbers: ");
scanf("%d,%d", &a, &n);
sum = a * a + n * n;
printf("\nSum of squares is: %d", sum);
break;
case 4:
exit(1);
default:
printf("\nInvalid choice");
}
}
}
WHAT'S NEW?
Loading...
0 comments:
Post a Comment