[go: up one dir, main page]

0% found this document useful (0 votes)
21 views6 pages

Assignment

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 6

1) #include<stdio.

h>

void repeating_element(int arr[],int n)//function declaration

int i,j;

int count=0;

printf("THE REPEATED ELEMENT:");//display

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

for(j=i+1;j<n;j++)//loop2

if(arr[i]==arr[j])

printf("%d ",arr[j]);

int main()//main function

int n;

printf("ENTER THE NUMBER OF ELEMENTS:\n");

scanf("%d",&n);

int arr[n];

int i;

printf("ENTER THE ELEMENTS:\n");

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

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

}
repeating_element(arr,n);//linking

return 0;

2)// Merge two sorted arrays array1 [u] and array2[v], the array elements should remain as sorted.

#include <stdio.h>

#include <stdlib.h>

int merge_two_sorted_arrays(int arr1[], int arr2[], int arr3[], int m, int n)

int i,j,k;

i = j = k = 0;

for(i=0;i < m && j < n;)

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

arr3[k] = arr1[i];

k++;

i++;

else

arr3[k] = arr2[j];

k++;

j++;

while(i < m)

{
arr3[k] = arr1[i];

k++;

i++;

while(j < n)

arr3[k] = arr2[j];

k++;

j++;

int main()

int n,m;

printf("\nEnter the size of Array 1 : ");

scanf("%d",&m);

printf("\nEnter the size of Array 2 : ");

scanf("%d",&n);

int arr1[m+1000],arr2[n];

int arr3[m+n];

int i;

printf("\nInput the Array 1 elements : ");

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

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

printf("\nInput the Array 2 elements : ");


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

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

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

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

arr1[i]=arr3[i];

printf("\nThe Merged Sorted Array : ");

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

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

printf("\n");

return 0;

3)// Find the missing numbers in an array and also check whether the number that’s missing is even
or odd.

#include<stdio.h>

#include<conio.h>

void main(){

int i,n,sum=0,missingnum;

printf("enter the size of the array:\n");

scanf("%d",&n);

int arr[n-1];

printf("enter the values:\n");

for(i=0;i<n-1;i++){
scanf("%d",&arr[i]);

sum=sum+arr[i];

missingnum =(n*(n+1))/2-sum;

printf("the missing number is = %d\n",missingnum);

if((missingnum%2)==0)

printf("The missing number is an even number");

else

printf("The missing number is an an odd number");

return 0;

4) //program to print the largest and the smallest element in an unsorted array

#include<stdio.h>

int main()

int a[100],i,n,SMALL,LARGE;

printf(“\n Enter the number of elements”);

scanf(“%d”,&n);

printf(“\n Input the array elements”);

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

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

LARGE=SMALL =a[0];

for(i=1;i<n;++i)//loop for calculation

if(a[i]>LARGE)
LARGE=a[i];//largest element

if(a[i]<SMALL)

SMALL=a[i];//smallest element

printf(“\n THE SMALLEST ELEMENT IS: %d\n”,SMALL);//displays the smallest element

printf(“\n THE LARGEST ELEMENT IS:%d\n”,LARGE);//displays the largest element

return 0;

You might also like