0% found this document useful (0 votes)
6 views2 pages

CPD PBL Ex

Uploaded by

muhammadzwasie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

CPD PBL Ex

Uploaded by

muhammadzwasie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

• Write a program to search the given number in an array of size 20.

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

You might also like