Write a C function to search a number in the given list of
numbers. donot use printf and scanf

Answer Posted / abdur rab

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main ( int argc, char* argv[] )
{
int array [ 10 ] = { 546, 541, 128, 1027, 1000,
10234, 657, 343, 111, 272 };
char _variable [ 50 ];
int _count = 0;
int _value = 0;

memset ( _variable, '\0', 50 );
puts ("Enter the number to search: ");
gets ( _variable );

_value = atoi ( _variable );

for ( _count = 0; _count < 10; _count++ ) {
if ( array [ _count ] == _value ) {
puts ("Search SUCCESSFUL");
return ( 0 );
}
}
puts ("Search NOT SUCCESSFUL");
return ( 1 );
}

If u guys really want to check the given input is numeric,
use isnumeric function defined in ctypes.h

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you define a string?

649


Can include files be nested? How many levels deep can include files be nested?

649


Why do we need functions in c?

544


What is nested structure in c?

600


Is that possible to add pointers to each other?

888






What is the difference between printf and scanf )?

581


What is non linear data structure in c?

561


What does calloc stand for?

641


What is the benefit of using const for declaring constants?

579


What is an endless loop?

796


Difference between linking and loading?

686


What will be the outcome of the following conditional statement if the value of variable s is 10?

754


what is diffrence between linear and binary search in array respect to operators?what kind of operator can be used in both seach methods?

1444


What is variable initialization and why is it important?

609


What are the loops in c?

589