1. Write a c program to reverse any number.

2. Write a c program to find out sum of digit of given number.

2. Write a c program to find out sum of digit of given number.

10. Write a c program to find out NCR factor of given number.

11. How to convert string to int without using library functions in c

12. Program in c to print 1 to 100 without using loop

13. C program for swapping of two numbers

14. Program to find largest of n numbers in c

15. Split number into digits in c programming

16. C program to count number of digits in a number

11. How to convert string to int without using library functions in c

12. Program in c to print 1 to 100 without using loop

13. C program for swapping of two numbers

14. Program to find largest of n numbers in c

15. Split number into digits in c programming

16. C program to count number of digits in a number

sir (~) tiled use karne se two number add kyun hue...kya aap xplain kr sakte h...

ReplyDeleteBH JUYHC

Delete@mohit

ReplyDeletea+b=a-(-b)

but we know -b=(~b+1)

so

a+b=a - (~b+1)

a+b= a - ~b - 1

I m just getting crazy in making c problems and i have completed all my assignments and problems that i had in handouts or pdf's and now i got this site as a helping tool to improve my skill to professional level..... Thankx man.. for giving us problems.... :) mean c problems.... ;)

ReplyDeletehere is a simple logic...adding a and b..say a=5 b=4 so a+b=5+4=9

ReplyDeleteint main(void)

{

int a=5,b=4;// you can input those nos from user...

while(b)

{

a++;

b--;

}

printf("%d",a);

}

i cant understand

DeleteGood thing boss

Deletestill not clear with '~'...

ReplyDelete'~' is a type of bitwise operator.

DeleteThis simply means one's complement.

Bitwise operators can only be operated upon ints & chars.

On taking the one's complement of a number, all the 1's are changed to 0's and vice-versa.

e.g: one's complement of 5 (0101) is -6 (1010).

~b = -(b+1)

ReplyDeleteso a-(~b)-1 = a-(-(b+1))-1

= a+b+1-1

= a+b

This code doesn't use any arithmetic operators to add two numbers.

ReplyDeletemain()

{

int num1, num2;

scanf("%d %d",num1, num2);

printf("%d", Add(num1, num2));

}

int Add(int x, int y)

{

if (y == 0)

return x;

else

return Add( x ^ y, (x & y) << 1);

}

please write explanation also. . .

Deletewhile (num2) // do until carry

ReplyDelete{

int carry = num1 & num2 // if its 1 & 1 we get carry

num1 = num1 ^ num2; // add all 0 +1 = 1

num2 = carry << 1; // now we need to carry

}

return num1

while (num2) // do until carry

ReplyDelete{

int carry = num1 & num2 // if its 1 & 1 we get carry

num1 = num1 ^ num2; // add all 0 +1 = 1

num2 = carry << 1; // now we need to carry

}

return num1

while (num2) // do until carry

ReplyDelete{

int carry = num1 & num2 // if its 1 & 1 we get carry

num1 = num1 ^ num2; // add all 0 +1 = 1

num2 = carry << 1; // now we need to carry

}

return num1

plz also share the problem for multiplication with out using * operator!!!

ReplyDeleteHere is a slight modification that adds subtraction feature as well:

ReplyDelete/* Adds two signed integers. Does a subtract when cin = 1 */

int adder(int a, int b, int cin)

{

if (cin) b = ~b;

int carry = (a & b) << 1 | cin;

a ^= b;

b = carry;

while (b) {

carry = (a & b) << 1;

a ^= b;

b = carry;

}

return a;

}

you can as well use ^ operator.

ReplyDeletea^b will give you its sum.