Sei sulla pagina 1di 5

1) Number 69 (base 10) is in base 2: 1000101.

Number 69 (base 10) is in base 8: 105.


Number 69 (base 10) is in base 16: 45.
2) Number AF (base 16) is in base 10: 175.
Number 12570 (base 8) is in base 2: 1010101111000.
Number 12570 (base 8) is in base 10: 5496.
Number 12570 (base 8) is in base 16: 1578.

5) #include<stdio.h>

int main()
{
int side1, side2, side3;

printf("\n Please Enter Three Sides of a Triangle : ");


scanf("%d%d%d", &side1, &side2, &side3);

if(side1 + side2 > side3)


{
if(side2 + side3 > side1)
{
if(side1 + side3 > side2)
{
printf("\n This is a Valid Traingle");

}
else
{
printf("\n This is an Invalid Triangle");
}
}
else
{
printf("\n This is an Invalid Triangle");
}
}
else
{
printf("\n This is an Invalid Triangle");
}
return 0;
}

#include <stdio.h>
#define SIZE 10
 
int binary_search(int arr[], int target); // function declaration
 
int main()
{
    
    int arr[SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // sorted array
    int target; // number to be searched
    int index;  // index position of the target
    
    printf("Enter number to search: ");
    scanf("%d", &target);
    
    index = binary_search(arr, target);  
    
    if(index !=  -1)
    {
        printf("Item %d found at index %d.", target, index);
    }
    else
    {
        printf("Item %d not found.", target);    
    }  
    
    return 0;
}
 
/*
* binary_search() returns index position of the
* target item. Returns -1, if the target item is not found.
*/
 
int binary_search(int arr[], int target)
{
    /*
       variables to keep track of the index positions
       where we will search in the array
    */
    int low = 0, up = SIZE - 1, midpoint;    
    
    while(low <= up)
    {
        midpoint = (low + up) / 2;  // calculate midpoint
 
        if(target > arr[midpoint])
        {
            // proceed search to the right portion
            low = midpoint + 1;
        }
        
        else if(target < arr[midpoint])
        {
            // proceed search to the left portion
            up = midpoint - 1;
        }
        
        else if(target == arr[midpoint])
        {
            // target value found. Return the index and exit the function
            return midpoint;
        }        
    }
    
    // target value not found, return -1 and exit the function
    return -1;
}

#include <stdio.h>

void main()

long int arr[10], Oddarr[10], Evenarr[10];

int i, j = 0, k = 0, n;

printf("Enter the size of array n");

scanf("%d", &n);

printf("Enter the elements of the array ");

for (i = 0; i < n; i++)

scanf("%ld", &arr[i]);

fflush(stdin);

}
/* Copy odd and even elements into their respective arrays */

for (i = 0; i < n; i++)

if (arr[i] % 2 == 0)

Evenarr[j] = arr[i];

j++;

else

Oddarr[k] = arr[i];

k++;

printf("The elements of Oddarr are ");

for (i = 0; i < k; i++)

printf("%ldn", Oddarr[i]);

printf("The elements of Evenarr are ");

for (i = 0; i < j; i++)

printf("%ldn", Evenarr[i]);
}

Potrebbero piacerti anche