Saif
Uddin Bijoy

C

				
					// Basic Scatchard 

#include <stdio.h>
#include <string.h>
#include <math.h>

int main() {
  printf("Hello World!");
  return 0;
}
				
			
				
					1. Convert a decimal number to binary: This program uses recursion to convert a decimal number to its binary representation.

2. Print even or odd numbers in a given range: By using recursion, this program can print all the even or odd numbers within a specified range.

3. Calculate the length of a string: This program recursively calculates the length of a given string.

4. Calculate the power of a number: Using recursion, this program can calculate the power of a given number.

5. Find the largest number in an array: This program uses recursion to find the largest number in an array.

6. Count the occurrence of an element in an array: By employing recursion, this program counts the number of times a specific element appears in an array.

7. Find the first capital letter in a string: This program utilizes recursion to find the first capital letter in a given string.

8. Check if a number is divisible by 11 and 9: By using recursion, this program checks if a given number is divisible by both 11 and 9.

9. Find the sum of the proper divisors of a number: This program recursively calculates the sum of the proper divisors of a given number.

10. Find the frequency of vowels in a string: Using recursion, this program determines the frequency of vowels in a given string
				
			
				
					//Metricx Cross Multiplication

#include <stdio.h>

#define ROW1 2
#define COL1 3
#define ROW2 3
#define COL2 2

void printMatrix(int matrix[ROW1][COL2], int row, int col) {
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < col; j++) {
            printf("%d ", matrix[i][j]);
        }
        printf("\n");
    }
}

int main() {
    int matrix1[ROW1][COL1] = {
        {1, 2, 3},
        {4, 5, 6}
    };

    int matrix2[ROW2][COL2] = {
        {7, 8},
        {9, 10},
        {11, 12}
    };

    int result[ROW1][COL2] = {0};

    // Multiply matrix1 and matrix2
    for (int i = 0; i < ROW1; i++) {
        for (int j = 0; j < COL2; j++) {
            for (int k = 0; k < COL1; k++) {
                result[i][j] += matrix1[i][k] * matrix2[k][j];
            }
        }
    }

    // Print the resulting matrix
    printf("Resultant Matrix:\n");
    printMatrix(result, ROW1, COL2);

    return 0;
}
				
			
				
					// Convert a decimal number to binary

#include <stdio.h>


void decimalConvertFun(int decimalNumber){
    if(decimalNumber <= 1){
       printf("%d", decimalNumber);
        return;
    };
    decimalConvertFun(decimalNumber/2);
    printf("%d", decimalNumber%2);
}

int main() {

  int decimal_number;
    printf("Please Enter the decimal Number: ");
    scanf("%d", &decimal_number);
    decimalConvertFun(decimal_number);
  return 0;
}

				
			
				
					// Print even or odd numbers in a given range

#include <stdio.h>
#include <string.h>


void evenOutPut(int start, int end){
    if(start%2==0 && start<=end){
        printf("%d ", start);
    }
    if(start>=end){
        return;
    }
    evenOutPut(start+1,end);
}

void oddOutPut(int start, int end){
    if(start%2==1 && start<=end){
        printf("%d ", start);
    }
    if(start>=end){
        return;
    }
    oddOutPut(start+1,end);
}

int main() {

    int start, end;
    char outPutType[5];
    printf("Please Enter the Renge (start | end): ");
    scanf("%d %d", &start, &end);
    printf("Please type what you want to print (even / odd): ");
    scanf("%s", outPutType);

    if(end >= start && strcasecmp(outPutType, "odd") == 0){
        oddOutPut(start, end);
    }else if(end >= start && strcasecmp(outPutType, "even") == 0){
        evenOutPut(start, end);
    }else{
        printf("Please give a correct range and type\n");
    }

    printf("\n");
    return 0;
}

				
			
				
					// Calculate the length of a string

#include <stdio.h>
#include <string.h>

#define THESIZE 500

int stringSize(char giverstr[THESIZE], int temp){
    if(giverstr[temp] == '\0' || giverstr[temp] == '\n'){
        return 0;
    }
    return 1 + stringSize(giverstr, temp + 1);
}

int main() {

    char giverstr[THESIZE];
    printf("Please Enter the string: ");
    fgets(giverstr, sizeof(giverstr), stdin);

    printf("The Size of string is: %d", stringSize(giverstr, 0));
    return 0;
}

				
			
				
					// Calculate the power of a number

#include <stdio.h>


int powerFun(int num, int power){
    if(power<=0){
        return 1;
    }
    return num * powerFun(num, power-1);
}

int main() {

    int num, power;

    printf("Please Enter the Number and Power (Number Power): ");
    scanf("%d %d", &num, &power);

    printf("The Sum is: %d", powerFun(num, power));
    return 0;
}

				
			
				
					// Find the largest number in an array
#include <stdio.h>

void getLargest(int mainArray[], int sizeArr, int currentIndex, int *largestValue){

    if(currentIndex>=sizeArr){
        return ;
    }

    if(mainArray[currentIndex] > *largestValue){
        *largestValue = mainArray[currentIndex];
    }

    return getLargest(mainArray, sizeArr, currentIndex+1, largestValue);
}

int main() {

    int sizeArr;
    printf("Give the Size of Array: ");
    scanf("%d", &sizeArr);
    int mainArray[sizeArr];
    for(int i = 0; i< sizeArr; i++){
        printf("Give the Array value %d:" ,i);
        scanf("%d", &mainArray[i]);
    }

    int largestValue = mainArray[0];

    getLargest(mainArray, sizeArr, 0, &largestValue);

    printf("The Largest Value is: %d", largestValue);
    return 0;
}

				
			
				
					
// Count the occurrence of an element in an array
#include <stdio.h>

void getValueTime(int mainArray[], int sizeArr, int currentIndex, int checkIndex, int *comeTime){

    if(checkIndex >= sizeArr){
        return ;
    }

    if(mainArray[currentIndex] == mainArray[checkIndex]){
        *comeTime = *comeTime + 1;
    }

    return getValueTime(mainArray, sizeArr, currentIndex, checkIndex + 1, comeTime);
}

int main() {

    int sizeArr;
    printf("Give the Size of Array: ");
    scanf("%d", &sizeArr);
    int mainArray[sizeArr];

    for(int i = 0; i< sizeArr; i++){
        printf("Give the Array value %d: " ,i);
        scanf("%d", &mainArray[i]);
    }

    for(int i = 0; i< sizeArr; i++){
        int isPreviousCount = 1;
        if(i>0){
            for(int j = i-1; j >= 0; j--){
                if(mainArray[i] == mainArray[j]){
                    isPreviousCount = 0;
                }
            }
        }

        if(isPreviousCount == 1){
            int comeTime = 0;
            getValueTime(mainArray, sizeArr, i, i, &comeTime);
            printf("%d Comes %d Times\n", mainArray[i], comeTime);
        }
    }

    return 0;
}


				
			
				
					//  Find the first capital letter in a string

#include <stdio.h>

#define THESIZE 500

int checkFun(char giverstr[THESIZE], int temp){
    if(giverstr[temp] >= 65 && giverstr[temp] <= 90){
        return giverstr[temp];
    }
    return checkFun(giverstr, temp + 1);
}

int main() {

    char giverstr[THESIZE];
    printf("Please Enter the string: ");
    fgets(giverstr, sizeof(giverstr), stdin);

    printf("The Size of string is: %c", checkFun(giverstr, 0));
    return 0;
}

				
			
				
					// Check if a number is divisible by 11 and 9

#include <stdio.h>

int checkTheNumber(int givenNumber, int divisible[], int temp){

    if(temp >=  sizeof(divisible)/sizeof(divisible[0])){
        return 1;
    }

    if(givenNumber%divisible[temp] != 0){
        return 0;
    }

    return 1 * checkTheNumber(givenNumber, divisible, temp + 1);
}

int main() {

    int givenNumber;
    printf("Please give the number: ");
    scanf("%d", &givenNumber);

    int divisible[] = {11,9};

    if(checkTheNumber(givenNumber, divisible, 0)){
        printf("The number is divisible");
    }else{
        printf("The number is not divisible");
    }

    return 0;
}


				
			
				
					//  Find the sum of the proper divisors of a number

#include <stdio.h>

int divisorFun(int givenNumber, int temp){

    if(givenNumber == temp){
        return 0;
    }

    if(givenNumber%temp == 0){
        return temp + divisorFun(givenNumber, temp+1);
    }

    return 0 + divisorFun(givenNumber, temp+1);
}

int main() {

    int givenNumber;
    printf("Please give the number: ");
    scanf("%d", &givenNumber);

    printf("Sum of the proper divisors of %d is %d", givenNumber, divisorFun(givenNumber, 1));

    return 0;
}


				
			
				
					// Find the frequency of vowels in a string

#include <stdio.h>
#include <string.h>

#define THESIZE 500

int stringVowels(char giverstr[THESIZE], int temp){
    if(giverstr[temp] == '\0' || giverstr[temp] == '\n'){
        return 0;
    }
    switch(giverstr[temp]){
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
        case 'A':
        case 'E':
        case 'I':
        case 'O':
        case 'U':
            printf("%c ", giverstr[temp]);
        break;
    }
    return stringVowels(giverstr, temp+1);
}

int main() {

    char giverstr[THESIZE];
    printf("Please Enter the string: ");
    fgets(giverstr, sizeof(giverstr), stdin);

    stringVowels(giverstr, 0);

    return 0;
}

				
			
				
					#include <iostream>
#include <vector>

using namespace std;

vector<int> v;
int low, hi;

int linear_search(int target) {
    
    while(low<=hi){
        int mid = (low+hi)/2;
        if(v[mid] == target){
            return mid;
        }else if(v[mid] < target){
            low = mid + 1;
        }else{
            hi = mid - 1;
        }
    }
    return -1;
}

int main() {
    int n, x, val, res;
    cin >> n;
     cout << "provide the sorted values";
    for (int i = 0; i < n; i++) {
        cin >> x;
        v.push_back(x);
    }
    low = 0;
    hi = v.size() - 1;
    cout << "provide the search value";
    cin >> val;
    res = linear_search(val);
    if (res == -1) {
        cout << "Not found";
    } else {
        cout << "found index=" << res;
    }

    return 0;
}