Search an element from an given array using C
Hey guys once again welcome to the Decoders blog, I hope you all are doing well and today I'm present with another logic but this time with something different it is a C logic which will search for an element from a given array using C logic
Here's the code which you can go through...........
#include<stdio.h>
int main()
{
int num,i,n,array[50];
printf("Enter the elements for the array:\n");
//Storing the value for the array
for(i=0;i<6;i++)
{
scanf("%d",&array[i]);
}
//Displaying the array
printf("The required array is\n");
for(i=0;i<6;i++)
{
printf("%d\t",array[i]);
}
printf("\nEnter the number which you are searching for:\n");
scanf("%d",&num);
//Logic to search for the element from the given array
for(i=0;i<6;i++)
{
if(num==array[i])
{
num=i;
}
}
printf("The element you searched for is present at the position %d",num+1);
}
Comments
Post a Comment