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

#include<stdio.h> main() { int a[3]; int *I; a[0]=100;a[1]=200;a[2]=300; I=a; Printf(“%d\n”, ++*I); Printf(“%d\n”, *++I); Printf(“%d\n”, (*I)--); Printf(“%d\n”, *I); } what is the o/p a. 101,200,200,199 b. 200,201,201,100 c. 101,200,199,199 d. 200,300,200,100

1 Answers  


What does a run-time "null pointer assignment" error mean?

2 Answers  


In c language can we compile a program without main() function?

0 Answers  


Write a c program to read a positive number and display it in words.? ex: 123=one two three help me....

2 Answers  


What is the right type to use for boolean values in c?

0 Answers  


Find if a number is power of two or not?

1 Answers  


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.

4 Answers  


write a program to swap two variables a=5 , b= 10 without using third variable

5 Answers  


.find the output of the following program? char*myfunc(char*ptr) { ptr +=3; return (ptr); } int main() { char*x,*y; x="HELLO"; y=myfunc(x); printf("y = %s ",y); return 0; }

0 Answers  


pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space is used for seperation of words) no addtional memory used.i.e no temporary arrays can used.

4 Answers   Persistent, Valyoo,


What is Conio.h ?

2 Answers   TCS,


Is c is a low level language?

0 Answers  


Categories