Accepts a number and identify if it is an odd or even number. Print "EVEN" or "ODD" as…
- User
Accepts a number and identify if it is an odd or even number. Print "EVEN" or "ODD" as your output. Filenames: Seatwork_02_01.jpg, Seatwork_02_01.c Accept the room number, room capacity and the number of students enrolled in the semester. Output whether the room is “FULL” or “NOT FULL
- Assistant
”. If the number of students enrolled is equal to or greater than the room capacity, print "FULL". Otherwise, print "NOT FULL". Filenames: Seatwork_02_02.jpg, Seatwork_02_02.c
- User
C programs for the following: Accepts a number and identify if it is an odd or even number. Print "EVEN" or "ODD" as your output. Filenames: Seatwork_02_01.jpg, Seatwork_02_01.c Accept the room number, room capacity and the number of students enrolled in the semester. Output whether the room is “FULL” or “NOT FULL”.
- Assistant
Here are the C programs for the given tasks:
- Accepts a number and identify if it is an odd or even number. Print "EVEN" or "ODD" as your output.
code#include <stdio.h> int main() { int num; printf("Enter a number: "); scanf("%d", &num); if(num%2 == 0) { printf("EVEN"); } else { printf("ODD"); } return 0; }- Accept the room number, room capacity and the number of students enrolled in the semester. Output whether the room is “FULL” or “NOT FULL”.
code#include <stdio.h> int main() { int room_number, room_capacity, num_enrolled; printf("Enter the room number: "); scanf("%d", &room_number); printf("Enter the room capacity: "); scanf("%d", &room_capacity); printf("Enter the number of students enrolled: "); scanf("%d", &num_enrolled); if(num_enrolled >= room_capacity) { printf("FULL"); } else { printf("NOT FULL"); } return 0; } - User
how about instead of if else, use swtich case
- Assistant
Sure! Here are the updated programs using a switch case:
- Accepts a number and identify if it is an odd or even number. Print "EVEN" or "ODD" as your output.
code#include <stdio.h> int main() { int num; printf("Enter a number: "); scanf("%d", &num); switch(num%2) { case 0: printf("EVEN"); break; case 1: printf("ODD"); break; } return 0; }- Accept the room number, room capacity and the number of students enrolled in the semester. Output whether the room is “FULL” or “NOT FULL”.
code