This program is for searching a element with a array. This is a part of Mumbai University MCA Colleges C Programs MCA Sem 1
#include<conio.h>
#include<stdio.h>
#define size 100
void main()
{
int ar[size],i,n,key,found=0;
clrscr();
li:
printf("\nEnter the size of array");
scanf("%d",&n);
if((n<1)||(n>=size))
{
printf("\nArray size is invalid");
goto li;
}
printf("\nEnter the elements in array");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
printf("\nEnter the key number to search");
scanf("%d",&key);
for(i=0;i<n;i++)
{
if(ar[i]==key)
{
printf("\nThe key %d is found at position %d in the Array",key,i);
found=1;
}
}
if(found==0)
{
printf("The key %d is not found is the array",key);
}
getch();
}
Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.
#include<conio.h>
#include<stdio.h>
#define size 100
void main()
{
int ar[size],i,n,key,found=0;
clrscr();
li:
printf("\nEnter the size of array");
scanf("%d",&n);
if((n<1)||(n>=size))
{
printf("\nArray size is invalid");
goto li;
}
printf("\nEnter the elements in array");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
printf("\nEnter the key number to search");
scanf("%d",&key);
for(i=0;i<n;i++)
{
if(ar[i]==key)
{
printf("\nThe key %d is found at position %d in the Array",key,i);
found=1;
}
}
if(found==0)
{
printf("The key %d is not found is the array",key);
}
getch();
}
Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.
Download
No comments:
Post a Comment