Rujin is right, here is the code which compiles.. vishal@ubuntu:~/progs/c\ 11:04:37 AM >$ cat alg.c #include<stdio.h> int maxdiff(int arr[]); int main() { int p,arr[]={2,4,1,6,23,4}; p=maxdiff(arr); printf("\n MAX Diff is \t %d",p); return 0; } int maxdiff(int arr[]) { int diff=0,len,i,j; unsigned p; len=sizeof(arr)/sizeof(arr[0]); for(i=0;i<len;i++) { for(j=i;j<len;j++) { p=arr[j]-arr[i]; if((p-diff)>0) diff=p; } } return diff; } vishal@ubuntu:~/progs/c\ 11:04:40 AM >$ gcc alg.c -Wall
On Fri, Jul 1, 2011 at 7:20 AM, varun pahwa <varunpahwa2...@gmail.com> wrote: > actually u r passing arr,and receiving arr[] which actually receives the > first element address. So arr will be a reference to first address. so its > size will be 4 bytes and arr size will also be 4 bytes. so ur len contains > only 1. so ur loop runs only once.i hope it clears. > > On Thu, Jun 30, 2011 at 4:49 PM, ashwini singh <asingh...@gmail.com> wrote: >> >> still it's not working >> >> On Thu, Jun 30, 2011 at 4:42 PM, Rujin Cao <drizzle...@gmail.com> wrote: >>> >>> int maxdiff(int ); >>> int maxdiff(int arr[]); >>> The signatures of maxdiff function are not the same. >>> >>> On Fri, Jul 1, 2011 at 6:53 AM, ashwini singh <asingh...@gmail.com> >>> wrote: >>>> >>>> this code gives an error ([Warning] passing arg 1 of `maxdiff' makes >>>> integer from pointer without a cast) . Please explain the reasons. >>>> >>>> >>>> #include<stdio.h> >>>> #include<conio.h> >>>> int maxdiff(int ); >>>> main() >>>> { >>>> int p,arr[]={2,4,1,6,23,4}; >>>> p=maxdiff(arr); >>>> printf("\n MAX Diff is \t %d",p); >>>> getch(); >>>> } >>>> int maxdiff(int arr[]) >>>> { >>>> int diff=0,len,i,j; >>>> unsigned p; >>>> len=sizeof(arr)/sizeof(arr[0]); >>>> for(i=0;i<len;i++) >>>> { >>>> for(j=i;j<len;j++) >>>> { >>>> p=arr[j]-arr[i]; >>>> if((p-diff)>0) >>>> diff=p; >>>> } >>>> } >>>> return diff; >>>> } >>>> >>>> -- >>>> with regards, >>>> Ashwini kumar singh >>>> ECE Final yr. >>>> NIT Allahabad >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Algorithm Geeks" group. >>>> To post to this group, send email to algogeeks@googlegroups.com. >>>> To unsubscribe from this group, send email to >>>> algogeeks+unsubscr...@googlegroups.com. >>>> For more options, visit this group at >>>> http://groups.google.com/group/algogeeks?hl=en. >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to algogeeks@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >> >> >> >> -- >> with regards, >> Ashwini kumar singh >> ECE Final yr. >> MNNIT Allahabad >> Mobile: 7505519402 >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. > > > > -- > Varun Pahwa > B.Tech (IT) > 7th Sem. > Indian Institute of Information Technology Allahabad. > Ph : 09793899112 ,08011820777 > Official Email :: rit2008...@iiita.ac.in > Another Email :: varunpahwa.ii...@gmail.com > > People who fail to plan are those who plan to fail. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.