Find the Second Largest Element in a 1-D Array Without Sorting in C

This program finds the second largest element in a 1-D array in a single pass, without sorting the array. C Program #include <stdio.h> #include <limits.h> int main() { int arr[100], n, i; int largest = INT_MIN, second = INT_MIN; printf(“Enter number of elements: “); scanf(“%d”, &n); printf(“Enter %d elements:\n”, n); for (i = 0; i … Read more

Convert Celsius to Fahrenheit and Back Using Switch Statement in C

This program converts a given temperature from Celsius to Fahrenheit or Fahrenheit to Celsius, based on the user’s choice, using a switch statement. C Program #include <stdio.h> int main() { int choice; float temp, result; printf(“1. Celsius to Fahrenheit\n2. Fahrenheit to Celsius\n”); printf(“Enter your choice: “); scanf(“%d”, &choice); printf(“Enter temperature: “); scanf(“%f”, &temp); switch (choice) … Read more

Check Whether a Number Is a Palindrome Using a While Loop in C

This program checks whether a given number is a palindrome (reads the same forwards and backwards) using a while loop. C Program #include <stdio.h> int main() { int num, original, reversed = 0, remainder; printf(“Enter a number: “); scanf(“%d”, &num); original = num; while (num != 0) { remainder = num % 10; reversed = … Read more

Find Student Grade Using If-Else Ladder in C

This program determines a student’s grade based on marks obtained, using an if-else ladder. C Program #include <stdio.h> int main() { float marks; printf(“Enter marks obtained (out of 100): “); scanf(“%f”, &marks); if (marks < 0 || marks > 100) { printf(“Invalid marks.\n”); } else if (marks >= 90) { printf(“Grade: A+\n”); } else if … Read more

Calculate Area and Circumference of a Circle in C

This program reads the radius of a circle and calculates its area and circumference using basic arithmetic operators. C Program #include <stdio.h> int main() { float radius, area, circumference; const float PI = 3.14159; printf(“Enter the radius of the circle: “); scanf(“%f”, &radius); area = PI * radius * radius; circumference = 2 * PI … Read more

Find the Largest and Smallest Elements in a 1-D Array in C

This program finds the largest and smallest elements in a one-dimensional array by scanning through it once and keeping track of the current maximum and minimum. C Program #include <stdio.h> int main() { int n, i; int arr[100]; printf(“Enter number of elements: “); scanf(“%d”, &n); printf(“Enter %d elements: “, n); for (i = 0; i … Read more

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