Write A C Program To Find The Largest Among Three Numbers Using If Statement

You might also like

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

1.

write a c program to find the largest among three numbers


Using if Statement.
TITLE: Finding the Largest Among Three Numbers Using if
Statement.
INTRODUCTION: This program calculates and displays the
largest among three input numbers using the ‘if’ statement.
CODE:

OUTPUT:

DISCUSSION:
The program utilizes the ‘if’ statement to perform
conditional checks for finding the largest number.
Each ‘if’ and ‘else if’ block compares the given number with
the other two and decides the largest.
This is a straightforward approach to solving the problem
using simple conditional logic.
2. write a c program to check whether number is even or odd
using switch.
TITLE: Checking Even or Odd Using the Switch Statement
INTRODUCTION: This program demonstrates the use of the ‘switch’
statement in C to determine whether a given number is even or odd.
The ‘switch’ statement is a powerful tool for making decisions based
on specific conditions, providing an alternative to the more common
‘if’ and ‘else’ constructs.
CODE:

OUTPUT:

DISCUSSION: “switch” helps make decisions based on different values.


Dividing by 2 and checking the remainder is a quick way to tell even
from odd. This code illustrates how simple decisions can be tackled
efficiently using “switch”. It's a basic example of programming logic for
newcomers. Learning to use “switch” can be useful for various
scenarios. The core idea is about categorizing and responding to
different situations.
3. write a c program to check prime number using switch case.
TITLE: Checking Prime Numbers Using Switch Case
INTRODUCTION: This C program employs a “switch” case to
determine whether a given number is a prime number or not. The
“switch” case, usually used for multi-case branching, showcases its
versatility in handling prime number checks.
CODE:

OUTPUT:

DISCUSSION:
The program employs a “switch” case to examine whether a number
is prime. The program design is based on the idea that prime numbers
are divisible only by 1 and themselves. The first “switch” checks for
numbers 0 and 1 which are not prime by definition. The second
“switch” outputs the prime/non-prime result based on the value of
the “isPrime” variable. The program presents a clear example of how
“switch” cases can be used for more complex decision structures. This
code encapsulates an elementary but crucial concept in number
theory and coding - prime numbers and decision-making.
4. Write a program in C to read 10 numbers from keyboard
and find their sum and average.
TITLE: Calculating Sum and Average of Numbers
INTRODUCTION: This C program reads numbers from the keyboard,
calculates their sum and average, and provides an illustrative example
of input, calculation, and output processes.
CODE:

OUTPUT:

DISCUSSION: The program reads 10 numbers and calculates their sum


and average. It employs a loop to gather input and accumulate the
sum. The average calculation is corrected using 10.0 for accurate
results. Basic input/output operations and loops are showcased. The
code highlights the importance of proper division for precise
averages.
5. write a C program to find the factorial of a number.
TITLE: Calculating Factorial of a Number
INTRODUCTION: This C program calculates the factorial of a given
number, showcasing a basic example of iterative calculation using
loops.
CODE:

OUTPUT:

DISCUSSION: The program calculates the factorial of a given number


using a for loop. It handles negative numbers and presents an error
message. It now also considers the special case of factorial for 0. The
code demonstrates fundamental loop-based calculations. It
addresses possible edge cases and enhances accuracy. The program
encapsulates factorial computation and basic input/output.
6. write a c program to find the largest among three numbers Using
if Statement
TITLE:
INTRODUCTION:
CODE:
OUTPUT:
DISCUSSION:

You might also like