0% found this document useful (0 votes)
5 views

More C Programming Questions and Answers

The document contains C programming examples for checking if a number is even or odd, finding the largest of three numbers, and calculating the factorial of a number using a loop. Each example includes the necessary code and prompts for user input. These programs demonstrate basic control structures and input/output operations in C.

Uploaded by

tabrijali6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

More C Programming Questions and Answers

The document contains C programming examples for checking if a number is even or odd, finding the largest of three numbers, and calculating the factorial of a number using a loop. Each example includes the necessary code and prompts for user input. These programs demonstrate basic control structures and input/output operations in C.

Uploaded by

tabrijali6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C Programming Questions and Answers

2. Implement a C program that checks whether a number is even or odd.


#include <stdio.h>

int main() {
int number;
printf("Enter an integer: ");
scanf("%d", &number);

if (number % 2 == 0) {
printf("%d is even\n", number);
} else {
printf("%d is odd\n", number);
}

return 0;
}

3. Implement a C program that finds the largest of three numbers.


#include <stdio.h>

int main() {
int a, b, c;
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);

if (a >= b && a >= c) {


printf("%d is the largest\n", a);
} else if (b >= a && b >= c) {
printf("%d is the largest\n", b);
} else {
printf("%d is the largest\n", c);
}

return 0;
}

4. Implement a C program to calculate the factorial of a number using a loop.


#include <stdio.h>
int main() {
int n, i;
unsigned long long factorial = 1;

printf("Enter a positive integer: ");


scanf("%d", &n);

for(i = 1; i <= n; ++i) {


factorial *= i;
}

printf("Factorial of %d = %llu\n", n, factorial);


return 0;
}

You might also like