EmbLogic's Blog

Author Archives: Ankit Narang

Binary search for sorted arrays of 10 elements

#include<stdio.h> #define SIZE 10 int main() { int i,arr[SIZE],key; int l=0,h=SIZE-1,m; printf(“Enter the numbers in array\n”); for(i=0;i<SIZE;i++) { scanf(“%d”,&arr[i]); } printf(“Enter the key”); scanf(“%d”,&key); while(l<=h) { m=(l+h)/2; if(key==arr[m]) { printf(“Element %d is found at %d position”,key,m); break; } else if(key<arr[m]) … Continue reading

Posted in Data Structures with C | Leave a comment

Swapping without third variable

#include<stdio.h> int main() { int i,j; printf(“Enter the value of i:”); scanf(“%d”,&i); printf(“Enter the value of j:”); scanf(“%d”,&j); i=i+j; j=i-j; i=i-j; printf(“%d”,i); printf(“%d”,j); return 0; }

Posted in Data Structures with C | Leave a comment

To find Largest and Smallest no.s among five numbers entered from the user

#include<stdio.h> int main() { int a,b,c,d,e,largest,smallest; printf(“enter five integers\n”); scanf(“%d%d%d%d%d”, &a,&b,&c,&d,&e); largest = a; if (b > largest) { largest=b; } if (c > largest) { largest=c; } if (d > largest) { largest=d; } if (e > largest) { … Continue reading

Posted in Data Structures with C | Leave a comment

value of resistor color code using switch statement

#include<stdio.h> int main() { char i; printf(“Enter the value of i”); scanf(“%c”,&i); switch(i) { case ’0′: printf(“Black”); break; case ’1′: printf(“brown”); break; case ’2′: printf(“Red”); break; case ’3′: printf(“Orange”); break; case ’4′: printf(“Yellow”); break; case ’5′: printf(“Green”); break; case ’6′: … Continue reading

Posted in Data Structures with C, Uncategorized | Leave a comment