Intermedet Codeing
Intermedet Codeing
Week 1
Mahesh HU22CSEN0102094
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.
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 :
Out put :
Output :
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.
Output:
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.