CPD PBL Ex
CPD PBL Ex
The
number should be taken as input from the user.
#include <stdio.h>
#include <conio.h>
int search_number(int number, int array[ ], int size, int index)
{
for (int i = 0; i < size; i++)
{
if (array[i] == number)
{
index = i;
if (index != -1)
{
printf("The number %d is found at index %d.\n", number, index);
}
else
printf("The number %d is not found in the array.\n", number);
}
}
}
void main(void)
{
clrscr();
int array[20], number, index;
printf("Enter 20 numbers for the array:\n");
for (int i = 0; i < 20; i++)
{
scanf("%d", &array[i]);
}
printf("Enter the number to search: ");
scanf("%d", &number);
search_number(number, array, 20, index);
getch();
}
Page 1 of 2
Output:
20 different roll nos. were given as input, while the number searched is 21026.
Page 2 of 2