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
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 |
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 |
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 |
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 |
how to find the given number is prime or not?
What do you mean by c?
What is the difference between ‘g’ and “g” in C?
In which area global, external variables are stored?
Explain the binary height balanced tree?
what is c language?
What is the difference between pure virtual function and virtual function?
who invented c
What is a far pointer?What is the utility?
Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result
What is pass by value in c?
write a program to print infinte number