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

What is the size of a union variable?

0 Answers  


Tell me the use of bit field in c language?

0 Answers  


For what purpose null pointer used?

0 Answers  


Explain indirection?

0 Answers  


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

0 Answers  






How can variables be characterized?

0 Answers  


What is a stream?

0 Answers  


what is the most appropriate way to write a multi-statement macro?

1 Answers  


C language questions for civil engineering

0 Answers   Tech Mahindra,


Write a program which has the following seven functions. The functions should be: • main() this calls the other 6 functions • fget_long() a function which returns a long data type from a file • fget_short() a function which returns a short integer variable from a file • fget_float() a function which returns a floating point variable from a file • fprt_long() a function which prints its single, long argument into a file • fprt_short() a function which prints its single, short argument into a file • fprt_float() a function which prints its single, floating point argument into a file. You should use fscanf() to get the values of the variables from the input (the file) and fprintf() to print the values to the other file. Pay attention to using the correct format for each of the data types.

0 Answers  


what is diference between return 0 and return NULL??

3 Answers  


a simple c program using 'for' loop to display the output 5 4 3 2 1

2 Answers   Google,


Categories