1.
Temperature Conversion: Celsius to Fahrenheit & Vice Versa
#include <stdio.h>
#include <conio.h>
void main() {
int choice;
float temp, result;
clrscr();
printf("1. Celsius to Fahrenheit\n2. Fahrenheit to Celsius\nEnter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter temperature in Celsius: ");
scanf("%f", &temp);
result = (temp * 9 / 5) + 32;
printf("Temperature in Fahrenheit: %.2f", result);
break;
case 2:
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &temp);
result = (temp - 32) * 5 / 9;
printf("Temperature in Celsius: %.2f", result);
break;
default:
printf("Invalid Choice");
}
getch();
}
2. Find the Day (1–7)
#include <stdio.h>
#include <conio.h>
void main() {
int day;
clrscr();
printf("Enter day number (1-7): ");
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 day number");
}
getch();
}
3. Calculator (Simple)
#include <stdio.h>
#include <conio.h>
void main() {
float a, b, result;
char op;
clrscr();
printf("Enter expression (a + b): ");
scanf("%f %c %f", &a, &op, &b);
switch (op) {
case '+': result = a + b; break;
case '-': result = a - b; break;
case '*': result = a * b; break;
case '/':
if (b != 0)
result = a / b;
else {
printf("Division by zero!");
getch();
return;
}
break;
default:
printf("Invalid operator");
getch();
return;
}
printf("Result = %.2f", result);
getch();
}
4. Find Grade of Given Marks
#include <stdio.h>
#include <conio.h>
void main() {
int marks;
clrscr();
printf("Enter marks (0-100): ");
scanf("%d", &marks);
switch (marks / 10) {
case 10:
case 9: printf("Grade: A"); break;
case 8: printf("Grade: B"); break;
case 7: printf("Grade: C"); break;
case 6: printf("Grade: D"); break;
case 5: printf("Grade: E"); break;
default: printf("Grade: F (Fail)");
}
getch();
}
5. Find Radius, Circumference, and Volume of Cylinder
#include <stdio.h>
#include <conio.h>
#define PI 3.14
void main() {
int choice;
float radius, height, result;
clrscr();
printf("1. Area of Circle\n2. Circumference\n3. Volume of Cylinder\nEnter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter radius: ");
scanf("%f", &radius);
result = PI * radius * radius;
printf("Area = %.2f", result);
break;
case 2:
printf("Enter radius: ");
scanf("%f", &radius);
result = 2 * PI * radius;
printf("Circumference = %.2f", result);
break;
case 3:
printf("Enter radius and height: ");
scanf("%f %f", &radius, &height);
result = PI * radius * radius * height;
printf("Volume = %.2f", result);
break;
default:
printf("Invalid choice");
}
getch();
}
6. Remove All Vowels From a String
#include <stdio.h>
#include <conio.h>
void main() {
char str[100];
int i;
clrscr();
printf("Enter a string: ");
gets(str);
printf("String without vowels: ");
for (i = 0; str[i] != '\0'; i++) {
switch (str[i]) {
case 'a': case 'e': case 'i': case 'o': case 'u':
case 'A': case 'E': case 'I': case 'O': case 'U':
break;
default:
putchar(str[i]);
}
}
getch();
}
7. Print Number of Days in Month
#include <stdio.h>
#include <conio.h>
void main() {
int month;
clrscr();
printf("Enter month number (1-12): ");
scanf("%d", &month);
switch (month) {
case 4: case 6: case 9: case 11:
printf("30 days");
break;
case 2:
printf("28 or 29 days");
break;
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
printf("31 days");
break;
default:
printf("Invalid month");
}
getch();
}
8. Check if Alphabet is Vowel or Consonant
#include <stdio.h>
#include <conio.h>
void main() {
char ch;
clrscr();
printf("Enter an alphabet: ");
scanf(" %c", &ch);
switch (ch) {
case 'a': case 'e': case 'i': case 'o': case 'u':
case 'A': case 'E': case 'I': case 'O': case 'U':
printf("Vowel");
break;
default:
printf("Consonant");
}
getch();
}
9. Find Maximum Between Two Numbers
#include <stdio.h>
#include <conio.h>
void main() {
int a, b;
clrscr();
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
switch (a > b) {
case 1: printf("%d is maximum", a); break;
case 0: printf("%d is maximum", b); break;
}
getch();
}
10. Check Even or Odd
#include <stdio.h>
#include <conio.h>
void main() {
int num;
clrscr();
printf("Enter a number: ");
scanf("%d", &num);
switch (num % 2) {
case 0: printf("Even"); break;
case 1: printf("Odd"); break;
}
getch();
}
11. Check Positive, Negative or Zero
#include <stdio.h>
#include <conio.h>
void main() {
int num;
clrscr();
printf("Enter a number: ");
scanf("%d", &num);
switch (num > 0) {
case 1: printf("Positive"); break;
case 0:
switch (num < 0) {
case 1: printf("Negative"); break;
case 0: printf("Zero"); break;
}
}
getch();
}
12. Find Roots of Quadratic Equation
#include <stdio.h>
#include <math.h>
#include <conio.h>
void main() {
float a, b, c, d, root1, root2;
clrscr();
printf("Enter coefficients a, b and c: ");
scanf("%f%f%f", &a, &b, &c);
d = b * b - 4 * a * c;
switch (d > 0) {
case 1:
root1 = (-b + sqrt(d)) / (2 * a);
root2 = (-b - sqrt(d)) / (2 * a);
printf("Real and Distinct Roots: %.2f, %.2f", root1, root2);
break;
case 0:
switch (d == 0) {
case 1:
root1 = root2 = -b / (2 * a);
printf("Real and Equal Roots: %.2f, %.2f", root1, root2);
break;
case 0:
printf("Complex roots");
}
}
getch();
}