Hello can you help me please... im making the program that will display the smallest number using function in array...please help me...thank you in advance...hoping for your positive responds....

#include<stdio.h>

void accept();
void findsmallest(int num[],int size);
int a;
int main(void)
 {

   accept();
   getch();
   return 0;
 }

 void accept()
  {
    int size=0;
    int num[]=size;
    scanf("%d",size);


   for(a=0;a<size;a++)
    {
      scanf("%d",& num[a]);
      if(num[a]<small)
       {
	 num[a]=small;
	}
     }
   }

 void findsmallest(num,size);
  {
    return;
  }
}

Write your accept function this way
I have separated the data input and the smallest number calculation into 2 steps but you dont have to

void accept(int *a)
{
     int size =0,i=0;
     
     printf("Enter the size of the array\n");
     scanf("%d",&size);
     
     a = (int*)malloc(sizeof(int)*size);       // Size of the i/p array is dynamic
     
     for(i=0;i<size;i++)
     {
         printf("Enter the next integer\n");
         scanf("%d",&a[i]);
     }
     
     printf("The entered numbers are \n");
     
     for(i=0;i<size;i++)                   // Just for checking
         printf("%d\n",a[i]);
}          

int 
smallest(int* a)
{
     // Logic for finding the smallest number         
     return 0;
}

int
main(int argc, char *argv[])
{
          int *a;
          accept(a);     
          
          printf("The smallest number is %d\n",smallest(a));        
         
         free(a);
         return 0;
}

Edited 6 Years Ago by abhimanipal: n/a

Hello can you help me please... im making the program that will display the smallest number using function in array...please help me...thank you in advance...hoping for your positive responds....

#include<stdio.h>

void accept();  //should be void accept(void);
void findsmallest(int num[],int size);  //well done!
int a;           //should be removed
int main(void)
 {

   accept();
   getch();
   return 0;
 }

 void accept()
  {
    int size=0, a;    //a goes down here
    int num[]=size;
    scanf("%d",size);   //should be &size, not just size

     
   for(a=0,small=num[a];a<size;a++) //assign small a value
    {                               //unassigned local variables   
      scanf("%d",&num[a]);          //could have any value    
      if(num[a]<small)              //to start with    
       {
	 num[a]=small;     //wrong! see below
	}
     }
   }

 void findsmallest(num,size);
  {
    return;
  }
}

I'm trying to be nice here, but this program is making it tough. It never even calls findsmallest (which has ZERO code in it, BTW. The code for it is up in the accept function (where it should be for efficiency), but the logic is wrong:

if(num[a]<small)
       {
     num[a]=small;     //wrong -- remove this line

     small = num[a];  //correct -- use this one.
    }

If you want to find the smallest value, in the findsmallest function, I have no problems with that. Just remove the if statement from the accept function, and put it into the findsmallest. You'll also need to have a separate for loop for it, in findsmallest.

Then, just call findsmallest like the prototype shows, and be sure to print out the smallest value.

There are LOTS of C tutorials on the web, some video tutorials from major colleges and universities. There are LOTS of programs on the web that you can look at.

Please study up, and work on your programs. You're wrecking my blood pressure!! ;)

I'm trying to be nice here, but this program is making it tough. It never even calls findsmallest (which has ZERO code in it, BTW. The code for it is up in the accept function (where it should be for efficiency), but the logic is wrong:

if(num[a]<small)
       {
     num[a]=small;     //wrong -- remove this line

     small = num[a];  //correct -- use this one.
    }

If you want to find the smallest value, in the findsmallest function, I have no problems with that. Just remove the if statement from the accept function, and put it into the findsmallest. You'll also need to have a separate for loop for it, in findsmallest.

Then, just call findsmallest like the prototype shows, and be sure to print out the smallest value.

There are LOTS of C tutorials on the web, some video tutorials from major colleges and universities. There are LOTS of programs on the web that you can look at.

Please study up, and work on your programs. You're wrecking my blood pressure!! ;)

hello sir i have some question about in your post why is it that some of your post can't be seen the only that i can see is this one

if(num[a]<small)
       {
     num[a]=small;     //wrong -- remove this line

     small = num[a];  //correct -- use this one.
    }

i tried to copy this page to the desktop then i open i saw your some post.

Edited 6 Years Ago by jemz: n/a

This article has been dead for over six months. Start a new discussion instead.