write a c programme for add of two numbers with out use of
arthematic operators

Answers were Sorted based on User's Feedback



write a c programme for add of two numbers with out use of arthematic operators..

Answer / upendra pratap shahi

int xor, and, temp;
and = x & y;
xor = x ^ y;

while(and != 0 )
{
and <<= 1;
temp = xor ^ and;
and &= xor;
xor = temp;
}

Is This Answer Correct ?    5 Yes 0 No

write a c programme for add of two numbers with out use of arthematic operators..

Answer / ria

/*error!!! in this program if we give 28-02-2012 to 03-03-2012 then correct output is not showing*/


#include<stdio.h>
#include<conio.h>
#include<math.h>


int func(int x)
{
int y=0;
switch(x)
{
case 1: y=0;
break;
case 2: y=31;
break;
case 3: y=59;
break;
case 4: y=90;
break;
case 5: y=120;
break;
case 6: y=151;
break;
case 7: y=181;
break;
case 8: y=212;
break;
case 9: y=243;
break;
case 10: y=273;
break;
case 11: y=304;
break;
case 12: y=334;
break;
}
return y;
}


void main()
{
int day1,mon1,year1,day2,mon2,year2,ref,dd1,dd2,i;

printf("\n enter first day,month,year: ");
scanf("%d%d%d",&day1,&mon1,&year1);
printf("\n enter second day,month,year: ");
scanf("%d%d%d",&day2,&mon2,&year2);
ref=year1;
dd1=func(mon1);
dd1=dd1+day1;
dd2=0;
for(i=ref;i<year2;i++)
{
if(i%100==0)
{
if(i%400==0)
dd2++;
}
else
if(i%4==0)
dd2++;
}

dd2=dd2+func(mon2)+day2+((year2-ref)*365);
printf("\n no of days= %d",abs(dd2-dd1));
}

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Interview Questions

develop algorithms to add polynomials (i) in one variable

0 Answers   Ignou, TCS,


what is pointer ?

10 Answers   Kernex Micro Systems,


Is there anything like an ifdef for typedefs?

0 Answers  


How is a structure member accessed?

0 Answers  


What is a shell structure examples?

0 Answers  






What are local static variables?

0 Answers  


What is Full Form of C and Why We use C

23 Answers  


Write a program for the following series? 1 121 12321 1234321 123454321 12345654321 1234567654321 123456787654321 12345678987654321 1234567890987654321 123456789010987654321 12345678901210987654321 1234567890123210987654321 .........1234321............ ..........123454321............ ..........12345654321............ 7 8 9 0 1 Pls............?

5 Answers  


Why is main function so important?

0 Answers  


What is the meaning of 2d in c?

0 Answers  


How to implement a packet in C

0 Answers   Aricent,


main() { FILE *fs; char c[10]; fs = fopen(“source.txt”, ”r”); /* source.txt exists and contains “Vector Institute” */ fseek(fs,0,SEEK_END); fseek(fs,-3L,SEEK_CUR); fgets(c,5,fs); puts(c); }

1 Answers   Vector,


Categories