Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

:Part 1

:Question 1

>include <stdio.h#
;int temp

)(int main
{

;printf("Enter the temperature: ")


;scanf("%d", &temp)

{ if (temp < 18)


;printf("It's a bit chilly out!")

}
{ 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)

{ if (num < 0.0)


;printf("You entered a negative number.\n")
}
else if (num > 0.0)
{
;printf("You entered a positive number.\n")
else }
{
;printf("You entered 0.\n")
}
;return 0
}

Question 4:
>include <stdio.h#
;int m
)(int main
{

;printf("Enter student's score: "); scanf("%d", &m)

{ if (100 >= m && m >= 90)


;printf("The grade is A\n")

}
else if (89 >= m && m >=80)
;printf("The grade is B\n") {
}
else if (79 >= m && m >=70)
;printf("The grade is C\n") {
}

else if (69 >= m && m >=60)


;printf("The grade is D\n") {
}
{ else
;printf("The grade is F\n")

}
;return 0
}

:Question 4
#include <stdio.h>
int chr;
int main()
{

printf("Enter small character: "); scanf("%c", &chr);

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

;printf("Enter three numbers (saperated spacee): ")

;scanf("%d%d%d", &m, &t, &b)

{ if (m > b && m> t)

;printf("%d is the largest value.\n", m)

{ else if (t > m && t > b)

;printf("%d is the largest value.\n", t)

{ else if (b > m && b > t)

;printf("%d is the largest value.\n", b)

{ else

;printf("the values is equal")


}

;return 0

}
:Question 6
>include <stdio.h#
;int Age
)(int main
{

;printf("Enter your age: "); scanf("%d", &Age)

{ if (Age < 14)


;printf("You are sill a child.\n")

}
{ 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);

if (age == 1 && qualification == 1 && ownsCar == 1) {


printf("Congratulations! You are eligible for a driving license.\n");
} else {
printf("Sorry, you do not meet the eligibility criteria for a driving license.\n");

}
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

;printf("Enter an integer: "); scanf("%d", &m)

;int result = check_odd_even(m)

{ if (result == 0)

;printf("The input is even\n")

{ else

;printf("The input is odd\n")

;return 0

:Question 2
>include <stdio.h#

int add(int m, int t)

;return m + t

int subtract(int m, int t)


{

;return m - t

int multiply(int m, int t)

;return m * t

float divide(int m, int t) { if(t != 0)

return (float)m / t; else

;printf("Division by zero is not allowed.\n"); return 0

}
}

{ )(int main

;int e = 10, b = 5

;printf("Addition: %d + %d = %d\n", e, b, add(e,b))

;printf("Subtraction: %d - %d = %d\n", e, b, subtract(e,b))

;printf("Multiplication: %d * %d = %d\n", e, b, multiply(e,b))

if(b != 0)

;printf("Division: %d / %d = %.2f\n", e, b, divide(e,b))

;return 0

}
:Question 3
>include <stdio.h#

Function prototype //

;int max(int, int, int)

;int main() { int m, t, b

Taking input from user //

;printf("Enter three integers: "); scanf("%d %d %d", &m, &t, &b)

Displaying the maximum value //

;printf("The maximum value is: %d\n", max(m,t,b))

;return 0

Function to find and return the maximum of three integers //

{ int max(int m, int t, int b)

;if(m > t && m > b) return m

;else if(t > m && t > b) return t

else

;return b

:Question 4
>include <stdio.h#

Recursive function prototype //

;int sum(int num)

{ )(int main

;int number, result


Taking input from user //

;printf("Enter a positive integer: "); scanf("%d", &number)

Calling the recursive function and storing the result //

;result = sum(number)

Displaying the result //

;printf("Sum = %d\n", result)

;return 0

Recursive function definition //

{ int sum(int num)

if(num != 0)

return num + sum(num - 1); // Recursive call else

;return num

You might also like