0% found this document useful (0 votes)
15 views14 pages

Intermedet Codeing

this code about the intermedet code
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)
15 views14 pages

Intermedet Codeing

this code about the intermedet code
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/ 14

Intermediate Coding

Week 1
Mahesh HU22CSEN0102094

1. C Program to Compute Quo ent and Remainder:


CODE :

OUTPUT:

tracing of code:
We start by taking inputs for dividend and divisor. Let
s say we input 20 as the dividend and 3 as the divisor.
The program computes the quo ent of the division
using 20 / 3. The integer division 20 / 3 results in 6 as
it only considers the whole number part. Next the
program calculates the remainder of the division using
20 % 3. The opera on 20 % 3 gives a remainder of 2.
The program prints the quo ent and remainder. It
displays Quo ent = 6 and Remainder = 2.

2. C Program to Swap Two Numbers:


Code:

Out put :

tracing of code:
We start by taking inputs for two numbers a and b.
Let s say we input 5 for a and 10 for b. The program
temporarily stores the value of a in a variable called
temp. At this point temp holds the value 5. The
program then assigns the value of b (which is 10) to a
so a now becomes 10. Next it assigns the value stored
in temp (which is 5) to b so b now becomes 5. The
program then prints the swapped values. It displays
A er swapping a = 10 b = 5 .
3. C Program to Check Whether a Number is Even or
Odd
Code :

Out put :
tracing of code:
We start by taking input for an integer num. Let s say we
input 7. The program checks whether 7 is even or odd by
using the condi on 7 % 2 == 0. The modulus operator %
calculates the remainder of 7 divided by 2 which is 1.
Since the remainder is not 0 the condi on is false
indica ng that 7 is an odd number. The program then prints
7 is odd. to the console.
If instead we input 4 the condi on 4 % 2 == 0
evaluates to true because the remainder is 0. This means 4
is an even number and the program would print 4 is
even. to the console.
4. C Program to Find the Largest Number Among Three
Numbers:
Code :

Output :

Tracing of the code:


We start by taking input for three numbers: num1
num2 and num3. Suppose we input 12 25 and
7. The program first compares num1 (which is 12)
with num2 (25) and num3 (7) to check if 12 is greater
than or equal to both. Since 12 is not greater than 25
this condi on is false.
Next the program compares num2 (which is 25)
with num1 (code12) and num3 (7) to see if 25 is
greater than or equal to both. Since 25 is indeed
greater than both 12 and 7 this condi on is true.
Therefore the program prints Largest number = 25
to the console indica ng that 25 is the largest of the
three numbers.

5. C Program to Find the Roots of a Quadra c


Equa on:
Code :

Out put :

Tracing for this code :


We start by taking input for the coefficients a b
and c of the quadra c equa on. Suppose the inputs
are 1 -3 and 2 respec vely. The program first
calculates the discriminant using the formula b * b - 4
* a * c. With the given inputs this calcula on
becomes (-3) * (-3) - 4 * 1 * 2 which results in 9 - 8 =
1.
Since the discriminant is 1 which is greater than 0
the program determines that there are two dis nct
real roots. It then calculates these roots using the
formulas root1 = (-b + sqrt(discriminant)) / (2 * a) and
root2 = (-b - sqrt(discriminant)) / (2 * a). For our
inputs root1 is computed as (3 + sqrt(1)) / (2 * 1)
which simplifies to (3 + 1) / 2 = 4 / 2 = 2.00. Similarly
root2 is calculated as (3 - sqrt(1)) / (2 * 1) which
simplifies to (3 - 1) / 2 = 2 / 2 = 1.00.
The program then prints Roots are: 2.00 and 1.00
to the console indica ng the two dis nct real roots
of the quadra c equa on. If the discriminant had
been 0 the program would have found one real root
and printed it twice. If the discriminant had been
nega ve the program would have computed
complex roots and printed them in the format Roots
are: [realPart] + [imaginaryPart]i and [realPart] -
[imaginaryPart]i .
6. C Program to Check Leap Year:
Code :

Output :

Tracing for code :


We start by taking input for the year to be checked.
For example if we input 2024 the program first
calculates 2024 % 4 which equals 0 showing that
2024 is divisible by 4. Next it calculates 2024 % 100
which equals 24 indica ng that 2024 is not divisible
by 100. Since 2024 meets the condi on of being
divisible by 4 but not by 100 the program checks if it
is divisible by 400 using 2024 % 400 which results in
24 meaning it is not divisible by 400. As the first
condi on is sa sfied the program determines that
2024 is a leap year and prints 2024 is a leap year.

7. C Program to Check Whether a Number is Posi ve


or Nega ve:
Code :

Output
Tracing for code :
We start by inpu ng a number such as -5.75. The
program first checks if -5.75 is posi ve by evalua ng -
5.75 > 0 which is false. Then it checks if -5.75 is
nega ve by evalua ng -5.75 < 0 which is true. Thus
the program prints -5.75 is nega ve.
If the input were 3.14 the program would print
3.14 is posi ve because 3.14 is greater than 0. If the
input were 0 the program would print You entered
zero as 0 is neither posi ve nor nega ve.

8. C Program to Find the Size of int float double


and char
Code :
Output

Tracing for this code :


We start by running the program to determine the
sizes of various data types. For example the
program first calculates the size of int using sizeof(int)
which returns 4 bytes on most systems. It prints Size
of int: 4 bytes. Next the program calculates the
size of float using sizeof(float) which typically
returns 4 bytes and prints Size of float: 4 bytes. It
then calculates the size of double with sizeof(double)
which usually returns 8 bytes and prints Size of
double: 8 bytes. Finally the program calculates the
size of char using sizeof(char) which returns 1 byte
and prints Size of char: 1 byte. These results may
vary depending on the system architecture.

9. C Program to Mul ply Two Floa ng-Point Numbers


Code :

Output:

Tracing for this code:


We start by taking input for two floa ng-point
numbers. For example if we input 5.5 and 4.2 the
program first reads these values and stores them in
num1 and num2. It then calculates the product of
these two numbers using the formula product = num1
* num2. For the inputs 5.5 and 4.2 the
mul plica on results in 23.10. The program then
prints Product = 21.84
10. C Program to Check Whether a Character is a
Vowel or Consonant
Code:

OUTPUT :

Tracing
We start by taking input for a character to be
checked. For example if we input b the
program first converts it to lowercase which
remains b. It then checks if b is a vowel by
comparing it to a e i o
and u . Since b does not match any of these
vowels the program checks if b is a consonant
by confirming if it is between a and z .
Since b falls within this range the program
prints b is a consonant.
If the input were A the program would convert
it to lowercase a and iden fy it as a vowel
prin ng a is a vowel.
If the input were 1 the program would
recognize that 1 is not a le er and print 1 is not
a le er.

You might also like