write a program to initialize 5 integers va,ues in an array and also initialize a target number to be searched.if the target number is not found display the proper message
Answers
Answered by
0
Answer:
Hey pal,
I'm not sure of language in which you are asking to program. Let me go with C language for this explanation.
int arr[]={2,5,6,8,9}; //Initialize 5 integer values in a integer array
int target = 8; //Initialize target number to be searched
int flag=1; //Flag to know whether the number is present
for( int i = 0 ; i < 5 ; i++)
{
if( arr[i] == target )
{
printf("\n Number found");
flag = 0;
}
}
if( flag = 1 )
printf("Number not found");
FYI: The underlined text in above progam is comment not part of code.
But the above program can be writtern in short using python language.Be careful about indentation.
array=[1,5,3,6,8]
target=3
if target in array:
print('Target present')
else:
print('Target not present')
Hope this answer helps you!
Similar questions