C_se_coding

C_se_coding

Share

24/03/2023

Basic structure of C program

22/01/2023

14/12/2022

Program :-
To print reverse of given number

How it works:-

Here we did initialization for

dummy----->To store the entered value(i.e 'n') as you will come to know at the end of the program

n----------->To store number given by user.

rev----->To store the reverse of a number.It is initialized to zero

x---------->To store n%10.

First of all we got a number 'n' from user and then stored it in a dummy variable called as 'dummy' for restoring the value.(remember this point).

Now the main logic comes here:-

let the number 'n' be 321 and as 321>0,while loop gets executed

then x=321%10--->which is 1.

rev=0*10+1-------->1

n=321/10--------->32

The rev for the first loop ex*****on is rev=1.

Now the number 'n' has become '32' and n>0,while loop executes for 2nd time

then x=32%10--->which is 2.

rev=1*10+2-------->12

n=32/10--------->3

The rev when loop executed second time is rev=12.

Now the number 'n' has become '3' and n>0,while loop executes for 3rd time

then x=3%10--->which is 3.

rev=12*10+3-------->123

n=3/10--------->0

The rev when loop executed third time is rev=123.

Now as the number in variable 'n' is 0 which is not n>0 then the loop terminates.Then the final reverse is '123'.

So now I hope you understood why the dummy variable is used.It is because the value in 'n' becomes 0 at the end of the program so for restoring this value to print at the end we used 'dummy'(as from the 2nd point).

Finally it prints the value in 'rev'.

25/08/2022

Program :-
Swap two numbers using third variable

How it works?
Explanation :-
Here we initialized a,b,c

a---> for storing 1st number

b--->for storing second number

c---->for storing temporary variable

Now here goes the logic(let us take a=1 and b=3)

c=a, Therefore, c=1

a=b, Therefore a=3

b=c, Therefore b=1

Now the values of a and b are 3 and 1

The values of a and are printed.

Want your business to be the top-listed Computer & Electronics Service in Mumbai?
Click here to claim your Sponsored Listing.

Telephone

Website

Address


Mumbai
400001