Problem
Write a program that asks the user to input 10 integers and stored them in an array and then again asks user to input any single number that store in variable “Num” and program check whether the Num is in the array or not and then print "Number “Num” is in the array" or “Num” is not in the array".Solution - Code
#include<stdio.h>#include<conio.h>
#include<stdlib.h>
main()
{
int arr[10];
int i,num;
for (i=0;i<10;i++)
{
printf ("Enter number : ");
scanf ("%d",&arr[i]);
}
printf("\nEnter number to check: ");
scanf ("%d",&num);
for (i=0;i<10;i++)
{
if (num==arr[i])
{
printf ("Entered number is in the array\n");
break;
} if (i == 9)
printf ("Entered number is not in the array\n");
}
system("pause");
}
No comments :
Post a Comment
Note: Only a member of this blog may post a comment.