Hi all i am new to programming and after i learnt Pascal i try to learn C.I have working to this program and from the pinakas function i want to return to main the first negative value of the array or if there isn't a negative value to return the first value of the array.Here is the code
This code return me always the first value of the array and not the first negative value if there is.Code:#include<stdio.h> #define n 5 int *pinakas(int *pin); main() { int *ptr,pin[n],i; //fill the array printf("Dwse ta stoixeia toy pinaka :\n"); for(i=0;i<n;i++) scanf("%d",&pin[i]); ptr=pinakas(pin); printf("%d\n",*ptr); } int *pinakas(int *pin) { int k; for (k=0;k<n;k++) { if(*(pin+k)<0) return pin+k; else return pin; } }
Any help?



LinkBack URL
About LinkBacks



