Re: [algogeeks] questions related to C

2011-07-12 Thread Aniket Dutta
c=a+b then find b=c-a; if this b equals previous one then ok else overflow On 7/9/11, John Hayes wrote: > regarding question related to overflow > > int ovr_sum(int *sum,int a,int b) > { > *sum=a+b > if(*sum<0) > return -1; //overflow > else > return 0; //no problem with the

Re: [algogeeks] questions related to C

2011-07-09 Thread John Hayes
regarding question related to overflow int ovr_sum(int *sum,int a,int b) { *sum=a+b if(*sum<0) return -1; //overflow else return 0; //no problem with the sum (overflow don't occur) } On Sat, Jul 9, 2011 at 2:05 PM, John Hayes wrote: > generic swap can be written as -> #defi

Re: [algogeeks] questions related to C

2011-07-09 Thread John Hayes
generic swap can be written as -> #define Swap(T, a, b) {T temp = a; a=b; b=temp;} this is working fine in gcc On Sat, Jul 9, 2011 at 1:45 PM, saurabh singh wrote: > #include > #include > #include > #include > void swap(void *p1,void *p2,const unsigned size) > { > char *buff=(char*) malloc(siz

Re: [algogeeks] questions related to C

2011-07-09 Thread saurabh singh
#include #include #include #include void swap(void *p1,void *p2,const unsigned size) { char *buff=(char*) malloc(size*sizeof(char)); if(!buff) { perror("malloc"); exit(11); } memcpy(buff,p1,size); memcpy(p1,p2,size); memcpy(p2,buff,size); free(buff); return; } int main() { int a=12,b=24; char c='a'

Re: [algogeeks] questions related to C

2011-07-08 Thread vikas
Thanks very much for recommending. By the way, Solutions to any problem posted by anybody, will be available in some or other book. I also knows K&R is a good book. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on

Re: [algogeeks] questions related to C

2011-07-08 Thread saurabh singh
also programming paradigm lectures from stanford may help On Fri, Jul 8, 2011 at 4:25 PM, Naveen Kumar wrote: > read K&R > > On Fri, Jul 8, 2011 at 4:20 PM, vikas wrote: > > Q1 - write a generic macro to swap two values (int,float,double,pointers > as > > well ) > > > > Q2 - Implement your own m

Re: [algogeeks] questions related to C

2011-07-08 Thread Naveen Kumar
read K&R On Fri, Jul 8, 2011 at 4:20 PM, vikas wrote: > Q1 - write a generic macro to swap two values (int,float,double,pointers as > well ) > > Q2 - Implement your own malloc() and  free() function > > Q3 - Two unsigned ints given a, b you have add these numbers and return > the sum ...Make

[algogeeks] questions related to C

2011-07-08 Thread vikas
Q1 - write a generic macro to swap two values (int,float,double,pointers as well ) Q2 - Implement your own malloc() and free() function Q3 - Two unsigned ints given a, b you have add these numbers and return the sum ...Make sure in case of overflow return "error". -- You received this m