Tuesday, July 16, 2013
Monday, July 8, 2013
Linear Search
Linear Search
Linear Search in C
C Programming "Linear Search"
Linear Search in C
C Programming "Linear Search"
#include<stdio.h> int main() { int arr[10],i,value,index; printf("Please enter 10 values:\n"); for(i=0;i<10;i++) scanf("%d",&arr[i]); printf("\nEnter a value to be searched: "); scanf("%d",&value); index = -1; for(i=0;i<10;i++) { if(arr[i]==value) { index=i; break; } } if(index>=0) printf("Value found in Array at %d location",index); else printf("Value not found in Array"); return 0; }
LiBinary Search
Binary Search in C
C Programming "Binary Search" - See more at: http://www.programming-and-it-research-center.blogspot.com/#sthash.b5niQNhp.dpuf
Binary Search in C
C Programming "Binary Search" - See more at: http://www.programming-and-it-research-center.blogspot.com/#sthash.b5niQNhp.dpuf
bBinary Search
Binary Search in C
C Programming "Binary Search" - See more at: http://www.programming-and-it-research-center.blogspot.com/#sthash.b5niQNhp.dpuf
Binary Search in C
C Programming "Binary Search" - See more at: http://www.programming-and-it-research-center.blogspot.com/#sthash.b5niQNhp.dpuf
Binary Search
Binary Search
Binary Search in C
C Programming "Binary Search"
Binary Search in C
C Programming "Binary Search"
#include<stdio.h> int main() { int arr[10],i,max,min,mid,val,index; printf("Please enter 10 values in ascending order:\n"); for(i=0;i<10;i++) scanf("%d",&arr[i]); printf("\nEnter a value to be searched: "); scanf("%d",&val); max=9; min=0; index=-1; while(min<=max) { mid=(max+min)/2; if(val==arr[mid]) { index=mid; break; } if(arr[mid]>val) max=mid-1; else min=mid+1; } if(index>=0) printf("Value found in Array at %d location",index); else printf("Value not found in Array"); return 0; }
Tuesday, July 2, 2013
Star Pattern in C
Star pattern in C
Print the following pattern in C
#include <stdio.h>
int main()
{
int i, j, k;
for(i=1;i<=5;i++)
{
for(j=1;j<=6-i;j++)
{
printf("*");
}
for(k=1;k<i;k++)
{
printf(" ");
}
for(j=1;j<=6-i;j++)
{
printf("*");
}
printf("\n");
}
for(i=2;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
for(k=1;k<=5-i;k++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
Print the following pattern in C
int main()
{
int i, j, k;
for(i=1;i<=5;i++)
{
for(j=1;j<=6-i;j++)
{
printf("*");
}
for(k=1;k<i;k++)
{
printf(" ");
}
for(j=1;j<=6-i;j++)
{
printf("*");
}
printf("\n");
}
for(i=2;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
for(k=1;k<=5-i;k++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
Subscribe to:
Posts (Atom)