Design a program using an array that searches a number if it
is found on the list of the given input numbers and locate
its exact location in the list.

Answers were Sorted based on User's Feedback



Design a program using an array that searches a number if it is found on the list of the given inpu..

Answer / dartz

#include<stdio.h>
#include<conio.h>
void main()
{
int ch[100],m,n,flag=0;
printf("enter the limit value");
scanf("%d",&m);
for(int i=0;i<m;i++)
scanf("%d",&a[i]);
printf("enter the number u are searching for :");
scanf("%d",&n);
for(i=0;i<m;i++)
{
if(a[i]==n)
{
printf("%d number is found at the position %d in the
given array ",n,i);
i=m;// to come out from the loop when we found
searching number
flag=1;

}
}


if( flag = 0)
{
printf(" given number is not found in the list of array");

}




getch();
}

Is This Answer Correct ?    1 Yes 1 No

Design a program using an array that searches a number if it is found on the list of the given inpu..

Answer / ashwin kumar

dear no need of pointer for the above Question dear

#include<stdio.h>
#include<conio.h>
void main()
{
int ch[100],m,n,flag=0;
printf("enter the limit value");
scanf("%d",&m);
for(int i=0;i<m;i++)
scanf("%d",&a[i]);
printf("enter the number u are searching for :");
scanf("%d",&n);
for(i=0;i<m;i++)
{
if(a[i]==n)
{
printf("%d number is found at the position %d in the
given array ",n,i);
i=m;// to come out from the loop when we found
searching number
flag=1;

}
}


if( flag = 0)
{
printf(" given number is not found in the list of array");

}




getch();
}

Is This Answer Correct ?    0 Yes 1 No

Design a program using an array that searches a number if it is found on the list of the given inpu..

Answer / vignesh1988i

small mistake in above program.... in last printf pl. change

*(*(ptr+i)) as (*(ptr+i))

Is This Answer Correct ?    1 Yes 3 No

Design a program using an array that searches a number if it is found on the list of the given inpu..

Answer / vignesh1988i

here i have used a concpt of pointers .. ie. array of
pointers.... when you search for a number it may occur once
or more than it... i have designed for all cases.. that's
why i used pointers......................

#include<stdio.h>
#include<conio.h>
void main()
{
int ch[100],m,n,*ptr[20],count=0;
printf("enter the limit value");
scanf("%d",&m);
for(int i=0;i<m;i++)
scanf("%d",&a[i]);
printf("enter the number u are searching for :");
scanf("%d",&n);
for(i=0,k=0;i<m;i++)
{
if(a[i]==m)
{
count++;
ptr[k]=&a[i];
k++;
}
for(i=0;i<count;i++)
printf("the number occured %d times and found to be int
these addresses : %u ",count,*(*(ptr+i)));
getch();
}

Is This Answer Correct ?    1 Yes 5 No

Post New Answer

More C Interview Questions

how to impliment 2 or more stacks in a single dimensional array ?

1 Answers   iFlex, Microsoft,


How will you print TATA alone from TATA POWER using string copy and concate commands in C?

0 Answers   Amdocs, Apps Associates,


what is y value of the code if input x=10 y=5; if (x==10) else if(x==9) elae y=8; a.9 b.8 c.6 d.7

4 Answers   TCS,


sir, i cannot find the way how to write aprogram by using array on queue

1 Answers   IISIT,


what is the associativity of bitwise OR operator?

1 Answers  






Difference between macros and inline functions? Can a function be forced as inline?

0 Answers   HAL, Honeywell, Zomato,


a 'c' program to tell that the set of three coordinates lie on a same line

3 Answers   Persistent,


can you change name of main()?how?

3 Answers   HCL, Siemens,


I have a function which accepts a pointer to an int. How can I pass a constant like 5 to it?

3 Answers  


What are the two types of functions in c?

0 Answers  


Explain what are the different data types in c?

0 Answers  


Write a C program to read the internal test marks of 25 students in a class and show the number of students who have scored more than 50% in the test. Make necessary assumptions.

1 Answers  


Categories