Example of different question in c programming
#include <stdio.h>
int main() {
float physics, chemistry, biology, mathematics, computer, percentage;
printf("Enter marks in Physics, Chemistry, Biology, Mathematics, and Computer: ");
scanf("%f %f %f %f %f", &physics, &chemistry, &biology, &mathematics, &computer);
percentage = (physics + chemistry + biology + mathematics + computer) / 5.0;
if (percentage >= 90)
printf("Grade A\n");
else if (percentage >= 80)
printf("Grade B\n");
else if (percentage >= 70)
printf("Grade C\n");
else if (percentage >= 60)
printf("Grade D\n");
else if (percentage >= 40)
printf("Grade E\n");
else
printf("Grade F\n");
return 0;
}
#include <stdio.h>
int main() {
int num1, num2;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
if (num1 > num2)
printf("Maximum is %d\n", num1);
else
printf("Maximum is %d\n", num2);
return 0;
}
#include <stdio.h>
int main() {
int num1, num2, num3;
printf("Enter three numbers: ");
scanf("%d %d %d", &num1, &num2, &num3);
if (num1 >= num2 && num1 >= num3)
printf("Maximum is %d\n", num1);
else if (num2 >= num1 && num2 >= num3)
printf("Maximum is %d\n", num2);
else
printf("Maximum is %d\n", num3);
return 0;
}
#include <stdio.h>
int main() {
int num1, num2;
printf("Enter two integers: ");
scanf("%d %d", &num1, &num2);
if (num1 == num2)
printf("The integers are equal.\n");
else
printf("The integers are not equal.\n");
return 0;
}
#include <stdio.h>
int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
printf("Leap year.\n");
else
printf("Not a leap year.\n");
return 0;
}
#include <stdio.h>
int main() {
int age;
printf("Enter your age: ");
scanf("%d", &age);
if (age >= 18)
printf("You are eligible to cast your vote.\n");
else
printf("You are not eligible to cast your vote.\n");
return 0;
}
#include <stdio.h>
int main() {
int m, n;
printf("Enter an integer m: ");
scanf("%d", &m);
if (m > 0)
n = 1;
else if (m == 0)
n = 0;
else
n = -1;
printf("n is %d\n", n);
return 0;
}
#include <stdio.h>
int main() {
int num1, num2, num3;
printf("Enter three numbers: ");
scanf("%d %d %d", &num1, &num2, &num3);
if (num1 <= num2 && num1 <= num3) {
printf("Smallest: %d\n", num1);
if (num2 <= num3)
printf("Middle: %d\nLargest: %d\n", num2, num3);
else
printf("Middle: %d\nLargest: %d\n", num3, num2);
} else if (num2 <= num1 && num2 <= num3) {
printf("Smallest: %d\n", num2);
if (num1 <= num3)
printf("Middle: %d\nLargest: %d\n", num1, num3);
else
printf("Middle: %d\nLargest: %d\n", num3, num1);
} else {
printf("Smallest: %d\n", num3);
if (num1 <= num2)
printf("Middle: %d\nLargest: %d\n", num1, num2);
else
printf("Middle: %d\nLargest: %d\n", num2, num1);
}
return 0;
}
#include <stdio.h>
int main() {
float temperature;
printf("Enter temperature in Celsius: ");
scanf("%f", &temperature);
if (temperature < 0)
printf("Freezing weather\n");
else if (temperature >= 0 && temperature <= 10)
printf("Very Cold weather\n");
else if (temperature > 10 && temperature <= 20)
printf("Cold weather\n");
else if (temperature > 20 && temperature <= 30)
printf("Normal in Temp\n");
else if (temperature > 30 && temperature <= 40)
printf("It's Hot\n");
else
printf("It's Very Hot\n");
return 0;
}
#include <stdio.h>
int main() {
int side1, side2, side3;
printf("Enter the lengths of three sides of a triangle: ");
scanf("%d %d %d", &side1, &side2, &side3);
if (side1 == side2 && side2 == side3)
printf("Equilateral Triangle\n");
else if (side1 == side2 || side2 == side3 || side1 == side3)
printf("Isosceles Triangle\n");
else
printf("Scalene Triangle\n");
return 0;
}
#include <stdio.h>
int main() {
int angle1, angle2, angle3;
printf("Enter three angles of a triangle: ");
scanf("%d %d %d", &angle1, &angle2, &angle3);
if (angle1 + angle2 + angle3 == 180)
printf("A triangle can be formed with these angles.\n");
else
printf("A triangle cannot be formed with these angles.\n");
return 0;
}
#include <stdio.h>
int main() {
int units;
float totalAmount;
printf("Enter the units consumed: ");
scanf("%d", &units);
if (units <= 199)
totalAmount = units * 1.5;
else if (units >= 200 && units < 400)
totalAmount = units * 1.2;
else if (units >= 400 && units < 600)
totalAmount = units * 1.0;
else
totalAmount = units * 0.9;
if (totalAmount > 500)
totalAmount = totalAmount + (totalAmount * 0.15);
if (totalAmount < 1000)
totalAmount = 1000;
printf("Electricity Bill: Rwf %.2f\n", totalAmount);
return 0;
}
#include <stdio.h>
int main() {
int dayNumber;
printf("Enter a day number (1-7): ");
scanf("%d", &dayNumber);
if (dayNumber == 1)
printf("Sunday\n");
else if (dayNumber == 2)
printf("Monday\n");
else if (dayNumber == 3)
printf("Tuesday\n");
else if (dayNumber == 4)
printf("Wednesday\n");
else if (dayNumber == 5)
printf("Thursday\n");
else if (dayNumber == 6)
printf("Friday\n");
else if (dayNumber == 7)
printf("Saturday\n");
else
printf("Invalid day number\n");
return 0;
}
#include <stdio.h>
int main() {
int digit;
printf("Enter a digit (0-9): ");
scanf("%d", &digit);
if (digit == 0)
printf("Zero\n");
else if (digit == 1)
printf("One\n");
else if (digit == 2)
printf("Two\n");
else if (digit == 3)
printf("Three\n");
else if (digit == 4)
printf("Four\n");
else if (digit == 5)
printf("Five\n");
else if (digit == 6)
printf("Six\n");
else if (digit == 7)
printf("Seven\n");
else if (digit == 8)
printf("Eight\n");
else if (digit == 9)
printf("Nine\n");
else
printf("Invalid digit\n");
return 0;
}
#include <stdio.h>
int main() {
int monthNumber;
printf("Enter a month number (1-12): ");
scanf("%d", &monthNumber);
if (monthNumber == 1)
printf("January\n");
else if (monthNumber == 2)
printf("February\n");
else if (monthNumber == 3)
printf("March\n");
else if (monthNumber == 4)
printf("April\n");
else if (monthNumber == 5)
printf("May\n");
else if (monthNumber == 6)
printf("June\n");
else if (monthNumber == 7)
printf("July\n");
else if (monthNumber == 8)
printf("August\n");
else if (monthNumber == 9)
printf("September\n");
else if (monthNumber == 10)
printf("October\n");
else if (monthNumber == 11)
printf("November\n");
else if (monthNumber == 12)
printf("December\n");
else
printf("Invalid month number\n");
return 0;
}
#include <stdio.h>
int main() {
int monthNumber;
printf("Enter a month number (1-12): ");
scanf("%d", &monthNumber);
if (monthNumber == 1 || monthNumber == 3 || monthNumber == 5 || monthNumber == 7 ||
monthNumber == 8 || monthNumber == 10 || monthNumber == 12)
printf("Number of days: 31\n");
else if (monthNumber == 4 || monthNumber == 6 || monthNumber == 9 || monthNumber ==
11)
printf("Number of days: 30\n");
else if (monthNumber == 2)
printf("Number of days: 28 or 29\n");
else
printf("Invalid month number\n");
return 0;
}