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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of pointers in C?

622


What is the difference between #include and #include 'file' ?

607


Explain the difference between null pointer and void pointer.

673


Explain how do you use a pointer to a function?

641


Do you know the difference between malloc() and calloc() function?

616






Explain a pre-processor and its advantages.

634


What is call by value in c?

559


Describe newline escape sequence with a sample program?

659


What are the types of pointers?

603


What are the benefits of organizational structure?

575


if p is a string contained in a string?

1406


Which are low level languages?

637


When the macros gets expanded?

791


Why does not c have an exponentiation operator?

630


number of times a digit is present in a number

1544