write a c programme for add of two numbers with out use of
arthematic operators
Answers were Sorted based on User's Feedback
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 |
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 |
What is extern variable in c with example?
What are the different types of constants?
What is int main () in c?
what is the difference between arrays and linked list
26 Answers MAHINDRA, Tech Mahindra, Wipro,
There are 3 baskets of fruits with worng lables,one basket has apple,another basket has orange,another has combination of apple and orange,what is the least way of interchange the lables.
15 Answers Cisco, Google, MBT,
with out using main how to execute the program?
What are structures and unions? State differencves between them.
10. Study the code: void show() main() { show(); } void show (char *s) { printf("%sn",s); } What will happen if it is compiled & run on an ANSI C Compiler? A)It will compile & nothing will be printed when it is executed B)it will compile but not link C)the compiler will generate an error D)the compiler will generate a warning
Write a programme to find even numbers without using any conditional statement?
3 Answers ADD Software, Infosys,
what is the difference between declaration ,defenetion and initialization of a variable?
What are reserved words?
What is a stream in c programming?