c - Function run 2 times.? -
i made program, code compiled thought program takes 5 inputs user takes 10 inputs.
#include <stdio.h> int greatest_number(); int main() { greatest_number(); printf("greatest number %d", greatest_number()); return(0); } int greatest_number() { int a[6], x, i, z, y;
i don't know why loop takes 10 inputs user
programmed take 5 inputs for(x=0; x<5; x++) { printf("enter number:"); scanf("%d", &a[x]); } a[x]=0; x=0, i=1; y=0; z=a[x]; while(a[x]) { if(z>a[i]){ z=a[y]; }else { z=a[i]; y=i; } x++; i++; } return(z); }
in code snippet function greatest_number
called twice
greatest_number(); ^^^^^^^^^^^^^^^^^ printf("greatest number %d", greatest_number()); ^^^^^^^^^^^^^^^^^
the first call redundant , result discarded.
also seems entered elements have negative values (except last element has have understood sentinel value) function return sentinel value.
Comments
Post a Comment