Search This Blog

Wednesday 13 January 2016

Find position of element in array

CODE:

#include<stdio.h>
#include<conio.h>
void main()
{
    int i,n,a[5],found=0;
    clrscr();
    for(i=0;i<5;i++)
    {
        printf("Enter a[%d]",i);
        scanf("%d",&a[i]);
    }
    printf("Enter your number to match");
    scanf("%d",&n);
    for(i=0;i<5;i++)
    {
        if(n==a[i])
        {
            printf("\nnumber %d is on position %d",a[i],i+1);
            found = 1;
        }
        }
    if(found == 0)
            printf("your number is not found");

    getch();
}

No comments:

Post a Comment