JAVASCRIPT PROGRAM TO FIND WHETHER NUMBER 8 IS PRESENT IN THE GIVEN SET OF DATA

<html>
<body>
<script language="javascript">

var i, n,flag;

n=prompt("Enter the size of the Array");
var a = new Array(n);

for( i=1; i <= n; i++ )
{
   a[i]=prompt("Enter the element   :");
}
document.write("Given Elements are" + "<br>" );
for( i=1; i <= n; i++ )
{
   document.write(a[i]+"<br>" );
}

for( i=1; i <= n; i++ )
{
    if ( a[i] == 8 )
       flag=1;
else
    flag=0;
}

if ( flag == 1 )
{
     alert("8  is present in the given array");
}
else
{
    alert("8 is not present in the given array");
}
</script>
</body>
</html>

No comments:

Post a Comment