Menu-Driven Unit Converter Using Switch Statement in C

This program implements a menu-driven unit converter (kilometers to miles, Celsius to Fahrenheit) using a switch statement. C Program #include <stdio.h> int main() { int choice; float value, result; printf(“Unit Converter Menu\n”); printf(“1. Kilometers to Miles\n”); printf(“2. Celsius to Fahrenheit\n”); printf(“Enter your choice: “); scanf(“%d”, &choice); switch (choice) { case 1: printf(“Enter distance in kilometers: … Read more

Check Whether a Character Is a Vowel, Consonant, Digit, or Special Character in C

This program reads a character from the keyboard and, using if-else statements, determines whether it is a vowel, consonant, digit, or special character. C Program #include <stdio.h> int main() { char ch; printf(“Enter a character: “); scanf(” %c”, &ch); if ((ch >= ‘a’ && ch = ‘A’ && ch = ‘A’ && ch = ‘0’ … Read more

Implicit and Explicit Type Conversion by Dividing Two Integers in C

This program demonstrates implicit and explicit type conversion by dividing two integers to obtain a floating-point result. C Program #include <stdio.h> int main() { int a, b; printf(“Enter two integers: “); scanf(“%d %d”, &a, &b); int implicit_result = a / b; float explicit_result = (float) a / (float) b; printf(“Integer division (implicit truncation): %d\n”, implicit_result); … Read more

Sort an Array in Ascending Order Using Bubble Sort in C

This program sorts the elements of a 1-D array in ascending order using the bubble sort technique. C Program #include <stdio.h> int main() { int arr[100], n, i, j, temp; printf(“Enter number of elements: “); scanf(“%d”, &n); printf(“Enter %d elements:\n”, n); for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } for (i ... Read more

Display Number of Days in a Month Using Switch Statement in C

This program displays the number of days in a given month (1-12) using a switch statement, taking leap years into account for February. C Program #include <stdio.h> int main() { int month, year, days; printf(“Enter month (1-12): “); scanf(“%d”, &month); printf(“Enter year: “); scanf(“%d”, &year); switch (month) { case 1: case 3: case 5: case … Read more

Type Conversion Between int, float, and char Using printf() in C

This program reads an integer, a float, and a character, then displays them with printf() using the appropriate format specifiers, demonstrating type conversion between int and float. C Program #include <stdio.h> int main() { int i; float f; char c; printf(“Enter an integer: “); scanf(“%d”, &i); printf(“Enter a float: “); scanf(“%f”, &f); printf(“Enter a character: … Read more