#include<stdio.h>
main()
{
int a[10],i,s;
printf("Enter 10 nos.\n");
for(i=0;i<=9;i++)
scanf("%d",&a[i]);
printf("Enter search element");
scanf("%d",&s);
for(i=0;i<=9;i++)
if(a[i]==s)
{
printf("Found");
break;
}
if(i==10)
printf("Not found");
}
#include<stdio.h>
main()
{
int a[10],i,s;
printf("Enter 10 nos.\n");
for(i=0;i<=9;i++)
scanf("%d",&a[i]);
printf("Enter search no.");
scanf("%d",&s);
for(i=0;i<=9;i++)
if(a[i]==s)
{
printf("Found at location %d",i+1);
break;
}
if(i==10)
printf("Not found");
}
#include<stdio.h>
main()
{
int a[10],i;
printf("Enter 10 nos.\n");
for(i=0;i<=9;i++)
scanf("%d",&a[i]);
for(i=0;i<=9;i++)
{
if(a[i]<0)
a[i]=0;
}
printf("Array is:");
for(i=0;i<=9;i++)
{
printf("%d ",arr[i]);
}
}
#include<stdio.h>
main()
{
int a[10],i,j,temp;
printf("Enter 10 nos.\n");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(j=9;j>0;j--)
for(i=0;i<j;i++)
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
printf("Sorted Array\n");
for(i=0;i<10;i++)
printf("%d ",a[i]);
}
#include<stdio.h>
int binarysearch(int a[ ],int val,int n)
{
int li,ui,mi;
li = 0;
ui = n-1;
do{
mi=(li+ui)/2;
if(a[mi]==val)
break;
if( val > a[ mi ])
li = mi +1;
else
ui = mi - 1;
}while(li<=ui);
if(li<ui)
return mi;
else
return -1;
}
main()
{
int arr[10]={2,3,5,6,8,9,10,12,15,17};
int value , result , i;
printf("\nElements are ");
for(i= 0;i<=9;i++)
printf("%d",arr[i]);
printf("\nEnter a no to Search: ");
scanf("%d",&value);
result=binarysearch(arr,value,10);
if(result==-1)
printf("\nNot Found ...");
else
printf("\nFound at position %d", result);
}
#include<stdio.h>
main()
{
int n;
printf("Enter the no of element to store in the array: ");
scanf("%d",&n);
int a[n];
printf("Enter %d nos: ");
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
printf("%d ",a[i]);
}
}
#include<stdio.h>
main()
{
int n,s;
printf("Enter the no of element to store in the array: ");
scanf("%d",&n);
int a[n];
printf("Enter %d nos: ");
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
s=s+a[i];
}
printf("Sum is %d ",s);
}
#include<stdio.h>
main()
{
int n,c=0,i;
printf("Enter the no of element to store in the array: ");
scanf("%d",&n);
int a[n];
printf("Enter %d nos: ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]<0)
c=c+1;
}
printf("Total negative nos are %d",c);
}
#include<stdio.h>
main()
{
int n,c1=0,c2=0,i;
printf("Enter the no of element to store in the array: ");
scanf("%d",&n);
int a[n];
printf("Enter %d nos: ");
#include<stdio.h>
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]%2==0)
c1=c1+1;
else
c2=c2+1;
}
printf("Even nos are %d",c1);
printf("\nOdd nos are %d",c2);
}