Posts

Showing posts from November, 2023

c program

linear search program* // Take an array as input from the user. Search for a given number x and print the index at where x is present in the array. #include <stdio.h> int main(void) {   int n,x;   printf("Enter the positive size of the array: ");   scanf("%d",&n);     int arr[n];   printf("Enter the element of array: ");   for(int i=0; i<n; i++){   scanf("%d", &arr[i]);   }     printf("Enter which number you want to search: ");   scanf("%d",&x);      int found = 0;   for(int i = 0; i<n; i++){     if(arr[i]==x){       printf("The index is %d and the the number is %d",i, x);       found = 1;       break;     }     if(!found) {       printf("The index is not present");     }   }   return 0; }   

Binary Code Complete Tutorial.

Write 7 in different way   :  2^0 =  1 2^1 = 2 2^2 = 4 4+2+1 = 7 Here we use base 2 to convert this intiger Day 10: Binary Numbers | HackerRank Common binary number 0 = 0 1 = 1 2 = 10 3 = 11 4 = 100 5 = 101 6 = 110 7 = 111 8 = 1000 9 = 1001 10 = 1010 11 = 1011 12 = 1100 13 = 1101 14 = 1110 15 = 1111 Operations :- Binary 0+0=0 0+1=1 1+0=1 1+1=0 For Example the Binary :-    6 -> 110 +7 ->  111 ----------  1101 Verify your answers :- 1*2^0 =1 1*2^2 = 4 1*2^3 = 8              ----                 13 Two's Compliment Rule 1 :- Two's complement "Flip the bit add 1" Rule 2 :- "Extending the sign" 6 -> 110 ]3bits          Now I'm converting the number in 8 bits [00000+110] just add the Zero before the binary number started. Flip the bits or replace the bits where the 0 replace with 1   :-   11111001 11111001   ...

Hacker Rank code challenge.

Image