0% found this document useful (0 votes)
4 views2 pages

ITE 12 Exercise 10

This C program presents a menu with four options: calculating the sum of the first N numbers, checking if a number is odd or even, displaying all even numbers from 1 to N, and exiting the program. The user can select an option, and the program executes the corresponding functionality until the exit option is chosen. Input validation is included to ensure the user selects a valid menu option.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

ITE 12 Exercise 10

This C program presents a menu with four options: calculating the sum of the first N numbers, checking if a number is odd or even, displaying all even numbers from 1 to N, and exiting the program. The user can select an option, and the program executes the corresponding functionality until the exit option is chosen. Input validation is included to ensure the user selects a valid menu option.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>

int main() {
int choice,num,sum, N;
do{
printf("\n Menu\n\n");
printf("[1]Sum of N\n[2]Odd or Even\n[3]Display All Even Numbers from 1 to N\
n[4]Exit Program\n");
printf("\n\nChoose a Number: ");
scanf("%d", &choice);

if(choice < 1 || choice > 4){


printf("Enter A Valid Choice!!");
}

switch(choice){
case 1:{
int n, sum = 0, i = 1;
printf("Enter a number: ");
scanf("%d", &n);
while (i <= n) {
sum += i;
i++;
}
printf("The sum of the first %d number is: %d", n, sum);
break;
}
case 2:{
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0) {
printf("%d is Even\n", num);
} else {
printf("%d is Odd\n", num);
}
break;
}
case 3:{
int n;
printf("Enter a number: ");
scanf("%d", &n);
printf("Even numbers from 1 to %d are: ", n);
for (int i = 2; i <= n; i += 2) {
printf("%d ", i);
}
printf("\n");
break;
}
case 4:{
printf("Exiting program. Goodbye!");
choice = 0;
break;
choice = 0;
break;

default:
printf("Invalid choice. Exiting program.");
choice = 0;
break;
}
}
}while(choice !=0);
}

You might also like