
harwind
Selection Sort Program In C
I received this error for a binary search programme in C, despite the fact that it requested for inputs and produced the right output. The error message I received in the output window is shown below.
binarysearch.c: In function 'sort': binarysearch.c:22:5: warning:
implicit declaration of function 'bin'
[-Wimplicit-function-declaration]
bin(a,size);//invokes bin(int,int) to find element
^~~ binarysearch.c: At top level: binarysearch.c:24:6: warning: conflicting types for 'bin' void bin(int a[],int size)//finds element
using binary sort technique and return its index
^~~ binarysearch.c:22:5: note: previous implicit declaration of 'bin' was here
bin(a,size);//invokes bin(int,int) to find element
^~~
Enter size of array
How can I fix the problem?
What does the error indicate?
Why did it continue to ask for inputs after an error occurred?
I created two functions. As mentioned in this documentation, the first function, void sort(int a[],int size), used selection sort to sort the array and printed it before invoking the second function, void bin(int a[],int size), which used binary search to find an element and printed its position(index+1). The main function was then written.
The programme is as follows:
#include<stdio.h>
void sort(int a[],int size)//sorts array in ascending order
{
int min;
for(int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
if(a[j]>a[j+1])//checks if elements at position 'i' is greater than element at position (i+1) and exchanges values if true
{
min=a[j];
a[j]=a[j+1];
a[j+1]=min;
}
}
}
printf("Sorted array:");
for(int i=0;i<size;i++)//prints sorted array
{
printf("%d ",a[i]);
}
bin(a,size);//invokes bin(int,int) to find element
}
void bin(int a[],int size)//finds element using binary sort technique and return its index
{
int key;//stores element to be found
printf("\nEnter element to be found:");
scanf("%d",&key);
int sp=0;//stores starting point which is initially 0
int ep=size-1;//stores ending point which is initially one less than size of array
int mid;//stores average of sp and ep
int count=0;//counter
printf("Occurrence is:");
while(sp<=ep)
{
mid=(sp+ep)/2;
if(a[mid]>key)//to run loop for elements that are before mid
{
ep=mid-1;
}
else if(a[mid]<key)//to run loop for elements that are after mid
{
sp=mid+1;
}
else if(a[mid]==key)//when element is found
{
printf("%d",mid+1);
count+=1;
break;//to stop the loop
}
}
if(count==0)//in case element is not found
printf("ELEMENT NOT FOUND");
}
int main()
{
int n;//stores size of array
printf("Enter size of array:");
scanf("%d",&n);
int arr[n];//creates array of size n
printf("Enter elements:");
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
sort(arr,n);//invoke sort(int,int) function which later invokes bin(int,int) function
return 0;
}
Popular Backend topics

I maintain a project that lists hundreds of thousands of web pages, and I’d like to show a screenshot for each web page. There are alread...
New

I have this code in a file that’s used to … render templates.
require 'erb'
require 'ostruct'
MISSING_CONFIG_MARKER = :config_key_and_v...
New

Hello everyone,
I’ve started learning Elixir and Phoenix few months ago and while I mostly grasped Elixir’s functional concepts and Phoe...
New

Background
I am now trying Gradual type checking, as a consequence I am giving a shot to Gradient. As I see it, this is an alternative to...
New

Background
I am trying to up my Functional Programming (FP) skills and one of the things that newcomers first learn in FP is the Option T...
New

Background
I have recently been delving into more functional code. My objective right now is to get something similar to the IO Monad (in...
New

Background
I have a personal project that is an elixir desktop application for PC Windows. It works pretty well, but now I want to give i...
New

I wrote this code to calculate Fibonacci numbers by specifying the size. The results are correct, however the one thing that concerns me ...
New

Any recommendations on good resources for learning Elixir, Phoenix, and Ash?
New

Background
As I often do, I read books to learn and improve myself. I also enjoy teaching and helping others when I can, so this is somet...
New
Other popular topics

New

The V Programming Language
Simple language for building maintainable programs
V is already mentioned couple of times in the forum, but I...
New

Think Again 50% Off Sale »
The theme of this sale is new perspectives on familiar topics.
Enter coupon code ThinkAgain2021 at checkout t...
New

Create efficient, elegant software tests in pytest, Python's most powerful testing framework.
Brian Okken @brianokken
Edited by Kat...
New

Author Spotlight
Jamis Buck
@jamis
This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New

Author Spotlight
Rebecca Skinner
@RebeccaSkinner
Welcome to our latest author spotlight, where we sit down with Rebecca Skinner, auth...
New

Programming Ruby is the most complete book on Ruby, covering both the language itself and the standard library as well as commonly used t...
New

zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig.
General-purpose programming language and toolchain for maintaini...
New

Develop, deploy, and debug BEAM applications using BEAMOps: a new paradigm that focuses on scalability, fault tolerance, and owning each ...
New

This is a very quick guide, you just need to:
Download LM Studio: https://lmstudio.ai/
Click on search
Type DeepSeek, then select the o...
New
Backend>Questions
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /rails
- /python
- /js
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /haskell
- /java
- /onivim
- /typescript
- /svelte
- /kotlin
- /crystal
- /c-plus-plus
- /tailwind
- /react
- /gleam
- /ocaml
- /elm
- /flutter
- /vscode
- /ash
- /html
- /opensuse
- /centos
- /php
- /deepseek
- /zig
- /scala
- /sublime-text
- /lisp
- /textmate
- /debian
- /nixos
- /react-native
- /agda
- /kubuntu
- /arch-linux
- /django
- /revery
- /ubuntu
- /manjaro
- /spring
- /nodejs
- /diversity
- /deno
- /lua
- /julia
- /c
- /slackware