CS HOMEWORK Homework 05a last name first name initial two va
CS HOMEWORK
Homework_ 05a_ last name first name initial. two variables A and B in double. B, or if they are the same value, print the message to inform the user homework_ 05b_lastname first name initial .c one variable in integer determine if the input is even or odd homework_ 05c_lastnamefirstnameinitial .c a grade in number in double between 0 and 100 Output: print the grade in number with this criteria: grade lessthanorequalto 90 A;80 lessthanorequalto gradeSolution
program 1: largest of two number
#include <stdio.h>
int main()
{
double A, B; // taking two variables to store double
printf(\"Enter the numbers!\ \");
scanf(\"%lf %lf\", &A, &B); //getting two double from the user
if(A > B) //case when A is greater than B
{
printf(\"%.2lf is maximum\", A);
}
else if(B > A) //case when B is greater than A
{
printf(\"%.2lf is maximum\", B);
}else // case when both A and B are equal.
{
printf(\"both the number are equal.\");
}
return 0;
}
/-------------output--------------/
sh-4.2$ main
Enter the numbers!
10
20
20 is maximumsh-4.2
$ main
Enter the numbers!
30
4
30 is maximum
sh-4.2$ main
Enter the numbers!
10
10
both the number are equal
/---------------output ends-----------/
#Program 2: Number is odd or even
#include <stdio.h>
int main()
{
int num; // taking one variables to store integer
printf(\"Enter the number!\ \");
scanf(\"%d\", &num); //getting one int from the user
if(num % 2 == 0) //case when A divide by 2 leaves remainder 0 (% is modulu function)
{
printf(\"%d is even\", num);
}
else // else the num is odd
{
printf(\"%d is odd\", num);
}
return 0;
}
/-----------output-----------------/
sh-4.2$ main
Enter the number!
39
39 is oddsh-4.2$ main
Enter the number!
40
40 is even
/-------------output----------------/
program 3- Grades
#include <stdio.h>
int main()
{
double grade; // taking thr grade to store integer
printf(\"Enter the grade!\ \");
scanf(\"%lf\", &grade); //getting one grade from the user
if(grade > 100) //case when grade is greater than 100
{
printf(\"grade cannot be greater than 100\");
}
else if(grade < 0) //case when grade is less than 0
{
printf(\"grade cannot be less than 0\");
}else
{
if(grade>=90){
printf(\"Grade A\");
}else if(grade>=80 && grade <90){
printf(\"Grade B\");
}else if(grade>=70 && grade <80){
printf(\"Grade C\");
}else if(grade>=60 && grade <70){
printf(\"Grade D\");
}else{
printf(\"Grade F\");
}
}
return 0;
}
/-output------------/
Enter the grade!
110
grade cannot be greater than 100sh-4.2$ main
Enter the grade!
-10
grade cannot be less than 0
sh-4.2$ gcc -o main *.c
sh-4.2$ gcc -o main *.c
sh-4.2$ main
Enter the grade!
95
Grade A
/--------output-------/
Note: Feel free to ask questions/doubts. God bless you!!


