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

Practical Key DAE

Uploaded by

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

Practical Key DAE

Uploaded by

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

Q1. Write a C program that takes an integer as input from the user and checks whether it is odd or even.

#include <stdio.h>

int main() {

int number;

// Prompt the user to enter an integer

printf("Enter an integer: ");

scanf("%d", &number);

// Check if the number is even or odd

if (number % 2 == 0) {

printf("%d is even.\n", number);

} else {

printf("%d is odd.\n", number);

return 0;

Q2. Write a C program to find the factorial of a given number using a loop.

#include <stdio.h>

int main() {

int number;

unsigned long long factorial = 1; // Using unsigned long long to handle large factorials

// Prompt the user to enter a non-negative integer

printf("Enter a non-negative integer: ");

scanf("%d", &number);

// Check if the input is valid

if (number < 0) {

printf("Factorial is not defined for negative numbers.\n");

} else {

// Calculate the factorial using a loop

for (int i = 1; i <= number; i++) {

factorial *= i;

// Print the result

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

return 0;

You might also like