Professional Documents
Culture Documents
HW 3
HW 3
:Question 1
>include <stdio.h#
;int temp
)(int main
{
}
{ else
;printf("It seems pleasent!")
}
;return 0
}
:Question 2
1.
#include <stdio.h>
int m;
int main()
{
printf("Enter the number:");
scanf("%d", &m);
if (m % 2 == 0) {
printf("The number %d is even. /n", m);
}
else {
printf("The number %d is odd. /n", m);
}
return 0;
}
2.
>include <stdio.h#
)(int main
{
;double num
;printf("Enter a number: "); scanf("%lf", &num)
Question 4:
>include <stdio.h#
;int m
)(int main
{
}
else if (89 >= m && m >=80)
;printf("The grade is B\n") {
}
else if (79 >= m && m >=70)
;printf("The grade is C\n") {
}
}
;return 0
}
:Question 4
#include <stdio.h>
int chr;
int main()
{
if (chr == 'a') {
printf("the character is vowel\n");
}
else if (chr == 'e') {
printf("the character is vowel\n");
}
else if (chr == 'i') {
printf("the character is vowel\n");
}
else if (chr == 'o') {
printf("the character is vowel\n");
}
else if (chr == 'u') {
printf("the character is vowel\n");
}
else {
printf("The character is not vowel\n");
}
return 0;
}
:Question 5
>include <stdio.h#
;int m, t, b
)(int main
{ else
;return 0
}
:Question 6
>include <stdio.h#
;int Age
)(int main
{
}
{ else if (14 <= Age && Age < 18)
;printf("You are teenager now.\n")
}
;else if (18 <= Age && Age < 35) { printf("TYou are a man now.\n")
}
{ else
;printf("You are a senior citizen now.\n")
}
;return 0
}
:Question 7
#include <stdio.h>
int age, qualification, ownsCar;
int main()
{
printf("Enter your age (1 for above 18, 0 for below 18): "); scanf("%d", &age);
printf("Do you have a graduate qualification? (1 for yes, 0 for no): "); scanf("%d",
&qualification);
printf("Do you own a car? (1 for yes, 0 for no): "); scanf("%d", &ownsCar);
}
return 0;
}
:Question 8
>include <stdio.h#
;int m, t, b
)(int main
{
;printf("1. Addition\n")
;printf("2. Subtraction\n"); printf("3. Multiplication\n")
;printf("4. Division\n")
;printf("Enter the values of a and b: "); scanf("%d %d", &m, &t)
;printf("Enter your choice (1-4): "); scanf("%d", &b)
switch (b)
{
:case 1
;printf("Sum of %d and %d is: %d\n", m, t, m + t); break
:case 2
;printf("Difference of %d and %d is: %d\n", m, t, m - t); break
:case 3
;printf("Multiplication of %d and %d is: %d\n", m, t, m * t); break
:case 4
{ if (t != 0)
;printf("Division of %d by %d is: %.2lf\n", m, t, (double)m / t)
}
else
{
;printf("Error: Cannot divide by zero.\n")
}
:break; default
;printf("Invalid choice. Please enter a valid option (1-4).\n"); break
}
;return 0
}
:Part 2
:Question 1
>include <stdio.h#
int check_odd_even(int m) { if (m % 2 == 0)
;return 0
}
{ else
;return 1
}
}
)(int main
;int m
{ if (result == 0)
{ else
;return 0
:Question 2
>include <stdio.h#
;return m + t
;return m - t
;return m * t
}
}
{ )(int main
;int e = 10, b = 5
if(b != 0)
;return 0
}
:Question 3
>include <stdio.h#
Function prototype //
;return 0
else
;return b
:Question 4
>include <stdio.h#
{ )(int main
;result = sum(number)
;return 0
if(num != 0)
;return num