🔥🔥 Practice Question Chapter 3 🔥🔥 (Greatest Number Logic is lit 🔥🔥 )
🔥 🔥Greatest number by using nested if and else if statement 🔥 🔥
#include <stdio.h>
int main()
{
int a, b, c, d;
printf("Enter the FOur numbers to find Greatest\n");
scanf("%d%d%d%d", &a, &b, &c, &d);
if (a > b)
{
if (a > c)
{
if (a > d)
{
printf("The number %d is big", a);
}
else
{
printf("The number %d is big", d);
}
}
}
else if (b > c)
{
if (b > d)
{
printf("The number %d is big", b);
}
else
{
printf("The number %d is big", d);
}
}
else if (c > d)
{
printf("The number %d is big", c);
}
else
{
printf("The number %d is big", d);
}
return 0;
}
🔥Number is lowercase or not by using ascii value code from 97 to 122 there is lowercase in ascii value and from 65 to 90 UPPERCASE
#include <stdio.h>
int main()
{
char ch; //data tyoe is important in this char dont use the int in place of char
printf("Enter the number to check it is lower case or not:");
scanf("%c", &ch);
if (ch <= 122 && ch >= 97)
{
printf("The character %c is lowercase ", ch);
}
else
{
printf("The Character %c is not lowercase", ch);
}
return 0;
}
Leap year or not by dividing the year value to the 4 and 400 and compare to zero and then by using the or || logical operator
#include <stdio.h>
int main()
{
int year;
printf("Enter the year to check weather it is leap year or not=");
scanf("%d", &year);
if ((year % 4 == 0) || (year % 400 == 0))
{
printf("The %d year is the leap year", year);
}
else if (year % 100 == 0)
{
printf("The %d year is not the leap year", year);
}
else
{
printf("The %d year is not the leap year", year);
}
return 0;
}
Income Tax
#include <stdio.h>
int main()
{
float income, tax1, tax2, tax3;
printf("Enter Your Annual Income=\n");
scanf("%f", &income);
tax1 = income / 5;
tax2 = income / 20;
tax3 = income / 30;
if (income < 250000)
{
printf("You don't have to pay the income your income is %f", income);
}
else if (income < 500000 && income > 250000)
{
printf("You have to pay tax %f ", tax1);
}
else if (income < 1000000 && income > 500000)
{
printf("You have to pay tax %f ", tax2);
}
else if (income > 1000000)
{
printf("You have to pay tax %f ", tax3);
}
else
{
printf("Your data is invaid !!!!!!!!");
}
return 0;
}
Pass or not 🔥 🔥 (Check the possibility is more or not possibility is more 🔥 🔥)
#include <stdio.h>
int main()
{
int physics, chemistry, maths;
float total;
printf("Enter the number of Physics=\n");
scanf("%d", &physics);
printf("Enter the number of Chemistry=\n");
scanf("%d", &chemistry);
printf("Enter the number of Maths=\n");
scanf("%d", &maths);
total = (physics + chemistry + maths) / 3;
if ((total < 40) || physics < 33 || chemistry < 33 || maths < 33)
{
printf("you're percentage is %f and you're fail", total);
}
else
{
printf("you're percentage is %f and you're pass", total);
}
return 0;
}
Assign (=) and comparison Operator (==)
#include <stdio.h>
int main()
{
int a = 10;
if (a = 11) // = it is the assaign operator and == it is the compariosion operator
{
printf("I am 11 Year's");
}
else
{
printf("I am not 11 Year's");
}
return 0;
}
Comments
Post a Comment