top of page



#include <stdio.h>

#define MAX_SIZE 100


void merge_arrays(int arr1[], int arr2[], int m, int n, int arr3[]) {

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

while (i < m && j < n) {

if (arr1[i] < arr2[j]) {

arr3[k++] = arr1[i++];

} else {

arr3[k++] = arr2[j++];

}

}

while (i < m) {

arr3[k++] = arr1[i++];

}

while (j < n) {

arr3[k++] = arr2[j++];

}

}


int main() {

int arr1[MAX_SIZE], arr2[MAX_SIZE], arr3[MAX_SIZE];

int m, n, i;

printf("Enter the size of first array: ");

scanf("%d", &m);

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

for (i = 0; i < m; i++) {

scanf("%d", &arr1[i]);

}

printf("Enter the size of second array: ");

scanf("%d", &n);

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

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

scanf("%d", &arr2[i]);

}

merge_arrays(arr1, arr2, m, n, arr3);

printf("Merged array: ");

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

printf("%d ", arr3[i]);

}

return 0;

}

6 views0 comments


#include <stdio.h>

int main() {

float num1, num2;

char operator;


printf("Enter two numbers: ");

scanf("%f %f", &num1, &num2);


printf("Enter an operator (+, -, *, /): ");

scanf(" %c", &operator);


switch(operator) {

case '+':

printf("%.1f + %.1f = %.1f", num1, num2, num1 + num2);

break;

case '-':

printf("%.1f - %.1f = %.1f", num1, num2, num1 - num2);

break;

case '*':

printf("%.1f * %.1f = %.1f", num1, num2, num1 * num2);

break;

case '/':

printf("%.1f / %.1f = %.1f", num1, num2, num1 / num2);

break;

default:

printf("Invalid operator");

}

return 0;

}




#include <stdio.h>

int main() {

int n,m,i,j;

int a[100];

int choice;

printf("\nEnter the range of array : ");

scanf("%d",&n);

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

{

printf("\nEnter Element : ");

scanf("%d",&a[i]);

}

printf("\n----Before Sorting----\n");

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

{

printf("----%d",a[i]);

}

printf("\n----After Sorting----\n");

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

{

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

{

if(a[i]>=a[j])

{

int temp;

temp=a[i];

a[i]=a[j];

a[j]=temp;

}

}

}

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

{

printf("----%d",a[i]);

}

printf("\nEnter Your Choice(1/0) : ");

scanf("%d",&choice);

while(choice)

{

printf("\nEnter Your Choice(min=1/max=2) : ");

scanf("%d",&choice);

switch(choice)

{

case 1:

{

printf("\nHow Many Minimum Elements You Require : ");

scanf("%d",&m);

printf("\n");

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

{

printf("----%d",a[i]);

}

}

case 2:

{

printf("\nHow Many Maximum Elements You Require : ");

scanf("%d",&m);

printf("\n");

for(i=n-1;i>=(n-m);i--)

{

printf("----%d",a[i]);

}

}

default:

printf("\nRepeat");

}

}

}

5 views0 comments
bottom of page