- Write a complete C program that takes input from keyboard and Gives the name of day in the input of 1 to 7 and write an invalid message.#include<stdio.h>int main(){int day;printf("Enter number:");scanf("%d",&day);switch (day){case 1:printf("Sunday");break;case 2:printf("Monday");break;case 3:printf("Tuesday");break;case 4:printf("Wednesday");break;case 5:printf("Thursday");break;case 6:printf("Friday");break;case 7:printf("Saturday");break;default:printf("Invalid Date (Enter 1-7 only)");break;}return 0;}
- Write a complete C program that reads a value in the range of 1 to 12 and print the name of that month and the next month. Print error for any other input value.#include <stdio.h>int main() {int month;// Array containing the names of the monthsconst char *months[] = {"January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"};// Prompt the user for inputprintf("Enter a month number (1-12): ");scanf("%d", &month);// Check if the input is within the valid rangeif(month >= 1 && month <= 12) {// Print the current monthprintf("Current month: %s\n", months[month - 1]);// Determine the next month (handling December)int nextMonth = (month % 12);// Print the next monthprintf("Next month: %s\n", months[nextMonth]);} else {// Print an error message for invalid inputprintf("Error: Invalid month number. Please enter a number between 1 and 12.\n");}return 0;}
- write a program to find the grace mark for a student using switch, The user should enter the class obtained by the student and the number of subjects he has failed in. Use the following logic.
-If the student gets first class and the number of subjects he failed in is greater than 3 , then he does not get any grace. Otherwise the grace is of 5 marks per subject.
-If the student get second class and the number of subjects he failed in is greater than 2, then he does not get any grace. Otherwise the grace is of 5 marks per subject.
-If the student gets third class and the number of subjects he failed in is greater than 1, then he does not get any grace otherwise the grace of 5 marks.#include <stdio.h>int main() {int student_class, failed_subjects, grace_marks = 0;// Input the class obtained by the studentprintf("Enter the class obtained by the student (1 for First, 2 for Second, 3 for Third): ");scanf("%d", &student_class);// Input the number of subjects the student has failed inprintf("Enter the number of subjects the student has failed in: ");scanf("%d", &failed_subjects);// Calculate grace marks using switch-caseswitch (student_class) {case 1: // First classif (failed_subjects <= 3) {grace_marks = failed_subjects * 5;}break;case 2: // Second classif (failed_subjects <= 2) {grace_marks = failed_subjects * 5;}break;case 3: // Third classif (failed_subjects <= 1) {grace_marks = 5;}break;default:printf("Invalid class entered.\n");return 1; // Exit the program with an error code}// Output the grace marksprintf("The student gets %d grace marks.\n", grace_marks);return 0;}
0 Comments had been done yet:
Post a Comment