Write a C program to read 3 characters one by one and print the characters in a reverse order.
- Declare three character variables to store the input characters.
- Use the scanf function to read the characters one by one from the user.
- Print the characters in reverse order using the printf function.
- End the program.
#include <stdio.h>
int main()
{
char a, b, c;
printf("Enter first character: ");
scanf(" %c", &a);
printf("Enter second character: ");
scanf(" %c", &b);
printf("Enter third character: ");
scanf(" %c", &c);
printf("Characters in reverse order: %c %c %c\n", c, b, a);
return 0;
}
Thus the program to read 3 characters one by one and print the characters in a reverse order has been executed successfully.
Write a C program to read A values and check whether A is positive number or not.
- Declare a variable to store the input value A.
- Use the scanf function to read the value of A from the user.
- Check if the value of A is greater than zero.
- If A is greater than zero, print a message indicating that it's a positive number.
- Otherwise, print a message indicating that it's not a positive number. 6.End the program.
#include <stdio.h>
int main()
{
int A;
printf("Enter a number: ");
scanf("%d", &A);
if (A > 0)
{
printf("%d is a positive number.\n", A);
}
else
{
printf("%d is not a positive number.\n", A);
}
return 0;
}
Thus the program to read A values and check whether A is positive number or not has been executed successfully.
Write a program to find minimum between two fraction numbers using conditional operator or ternary operator.
- Declare variables to store the two fraction numbers and the result.
- Use the printf function to prompt the user to enter the first fraction number (numerator and denominator separately).
- Use the scanf function to read the numerator and denominator of the first fraction.
- Repeat steps 2 and 3 to get the second fraction from the user.
- Calculate the decimal values of both fractions by dividing the numerators by the denominators.
- Use the conditional (ternary) operator to compare the decimal values and store the minimum value in the result variable.
- Print the minimum value.
#include <stdio.h>
int main()
{
float num1, num2, min;
printf("Enter first number: ");
scanf("%f", &num1);
printf("Enter second number: ");
scanf("%f", &num2);
min = (num1 < num2) ? num1 : num2;
printf("Minimum number = %.2f\n", min);
return 0;
}
Thus the program to find minimum between two fraction numbers using conditional operator or ternary operator has been executed successfully.
Write a C program to check whether the input value is equal to 1 using simple if statement
- Declare a variable to store the input value.
- Use the scanf function to read the input value from the user.
- Use an if statement to check if the input value is equal to 1.
- If the condition in the if statement is true, print a message indicating that the input value is equal to 1.
- Otherwise, print a message indicating that it's not equal to 1.
- End the program.
#include <stdio.h>
int main()
{
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num == 1)
printf("The number is equal to 1.\n");
return 0;
}
Thus the program to check whether the input value is equal to 1 using simple if statement has been executed successfully
To write a C program that reads marks of three subjects, calculates the total and percentage, and then determines the division (First, Second, Pass, or Fail) based on the percentage and minimum marks criteria.
- Start
- Declare integer variables m1, m2, m3 for marks, and float variables tot, per.
- Input the marks for three subjects.
- Calculate total marks: tot = m1 + m2 + m3
- Calculate percentage: per = tot / 3
- Display total and percentage.
- Check if all marks are greater than or equal to 40:
- If yes: a. If percentage >= 60: Print “Division = First” b. Else if percentage >= 48: Print “Division = Second” c. Else if percentage >= 36: Print “Division = Pass”
- Else: Print “Division = Fail”
- End
#include <stdio.h>
int main()
{
int m1, m2, m3;
float tot, per;
printf("Enter marks of three subjects: ");
scanf("%d %d %d", &m1, &m2, &m3);
tot = m1 + m2 + m3;
per = tot / 3;
printf("\nTotal Marks = %.2f", tot);
printf("\nPercentage = %.2f%%\n", per);
if (m1 >= 40 && m2 >= 40 && m3 >= 40)
{
if (per >= 60)
printf("Division = First\n");
else if (per >= 48)
printf("Division = Second\n");
else if (per >= 36)
printf("Division = Pass\n");
else
printf("Division = Fail\n");
}
else
{
printf("Division = Fail\n");
}
return 0;
}
The program successfully takes three subject marks, calculates the total and percentage, and correctly determines the division based on predefined grading logic.




