Simple Calculator Using Switch Statement in C

This program builds a simple calculator that performs addition, subtraction, multiplication, and division based on the user’s menu choice, using a switch statement. C Program #include <stdio.h> int main() { int choice; float num1, num2, result; printf(“Enter two numbers: “); scanf(“%f %f”, &num1, &num2); printf(“Choose an operation:\n”); printf(“1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n”); printf(“Enter your choice … Read more

Check Triangle Type: Equilateral, Isosceles, Scalene, or Invalid in C

This program reads the three sides of a triangle and determines whether it is equilateral, isosceles, scalene, or not a valid triangle at all — using nested if-else statements. C Program #include <stdio.h> int main() { float a, b, c; printf(“Enter the three sides of the triangle: “); scanf(“%f %f %f”, &a, &b, &c); if … Read more

Swap Two Numbers Without Using a Third Variable in C

This program shows how to swap the values of two variables without using a temporary (third) variable, using arithmetic operators. C Program #include <stdio.h> int main() { int a, b; printf(“Enter value of a: “); scanf(“%d”, &a); printf(“Enter value of b: “); scanf(“%d”, &b); printf(“\nBefore swapping: a = %d, b = %d\n”, a, b); a … Read more