0% found this document useful (0 votes)
7 views

Assignment 12

Uploaded by

vrunurade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Assignment 12

Uploaded by

vrunurade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Q1)

#include<stdio.h>

#include<stdlib.h>

void store(int,int*);

void display(int,int*);

void minMax(int,int,int,int*);

void main(){

int size;

prin ("Enter the Size for the Array:");

scanf("%d",&size);

int*arr = (int*)malloc(sizeof(int)*size);

store(size,arr);

display(size,arr);

int min = arr[0] , max = arr[0];

minMax(min,max,size,arr);

void store(int size,int*arr){

prin ("\nEnter the Elements of the Array:\n");

int i;

for(i=0;i<size;i++) scanf("%d",&arr[i]);

void display(int size,int*arr){

int i;

prin ("The elements of Array are: ");

for(i=0;i<size;i++) prin ("%d ",arr[i]);

void minMax(int min,int max,int size,int*arr){

int i;

for(i=1;i<size;i++){

if(min > arr[i]) min = arr[i];

if(max < arr[i]) max = arr[i];


}

prin ("\nThe Smallest element Present in the array is %d",min);

prin ("\nThe largest element Present in the array is %d",max);

Q2)

#include<stdio.h>

#include<stdlib.h>

void store(int,int*);

void display(int,int*);

int search(int,int,int*);

void main(){

int size;

prin ("Enter the Size for the Array:");

scanf("%d",&size);

int*arr = (int*)malloc(sizeof(int)*size);

store(size,arr);

display(size,arr);

int key;

prin ("\nEnter the Element you want to search in the Array:");

scanf("%d",&key);

int i = search(size,key,arr);

if(i < size){

prin ("The element %d is present at the index %d",key,i);

else prin ("The element %d is not present in the array.",key);

void store(int size,int*arr){

prin ("\nEnter the Elements of the Array:\n");

int i;

for(i=0;i<size;i++) scanf("%d",&arr[i]);

}
void display(int size,int*arr){

int i;

prin ("The elements of Array are: ");

for(i=0;i<size;i++) prin ("%d ",arr[i]);

int search(int size,int key,int*arr){

int i;

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

if(key == arr[i]){

return i;

return i;

Q3)

#include<stdio.h>

void store(int,int*);

void display(int,int*);

int sum(int,int*);

void main(){

int size;

prin ("Enter the Size for the Array:");

scanf("%d",&size);

int*arr = (int*)malloc(sizeof(int)*size);

store(size,arr);

display(size,arr);

prin ("\nThe sum of all the Elements in the array is %d",sum(size,arr));

void store(int size,int*arr){

prin ("\nEnter the Elements of the Array:\n");

int i;
for(i=0;i<size;i++) scanf("%d",&arr[i]);

void display(int size,int*arr){

int i;

prin ("The elements of Array are: ");

for(i=0;i<size;i++) prin ("%d ",arr[i]);

int sum(int size,int*arr){

int sum = 0,i;

for(i=0;i<size;i++) sum+= arr[i];

return sum;

Q4)

#include<stdio.h>

void main(){

int size;

prin ("Enter the Size for the Array:");

scanf("%d",&size);

int*arr = (int*)malloc(sizeof(int)*size);

store(size,arr);

display(size,arr);

even(size,arr);

odd(size,arr);

void store(int size,int*arr){

prin ("\nEnter the Elements of the Array:\n");

int i;

for(i=0;i<size;i++) scanf("%d",&arr[i]);

void display(int size,int*arr){

int i;
prin ("\nThe elements of Array are: ");

for(i=0;i<size;i++) prin ("%d ",arr[i]);

void even(int size,int*arr){

int i;

prin ("\nThe Even Numbers in the Array are: ");

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

if(arr[i]%2 == 0) prin ("%d ",arr[i]);

void odd(int size,int*arr){

int i;

prin ("\nThe Odd Numbers in the Array are: ");

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

if(arr[i]%2 != 0) prin ("%d ",arr[i]);

Q5)

#include<stdio.h>

void store(int,int*);

void display(int,int*);

void alternate(int,int*);

void main(){

int size;

prin ("Enter the Size for the Array:");

scanf("%d",&size);

int*arr = (int*)malloc(sizeof(int)*size);

store(size,arr);

display(size,arr);

alternate(size,arr);

}
void store(int size,int*arr){

prin ("\nEnter the Elements of the Array:\n");

int i;

for(i=0;i<size;i++) scanf("%d",&arr[i]);

void display(int size,int*arr){

int i;

prin ("The elements of Array are: ");

for(i=0;i<size;i++) prin ("%d ",arr[i]);

void alternate(int size,int*arr){

int i;

prin ("\nThe alternate elements of Array are: ");

for(i=0;i<size;i+=2) prin ("%d ",arr[i]);

Q6)

#include<stdio.h>

void store(int,int*);

void display(int,int*);

void prime(int,int*);

void main(){

int size;

prin ("Enter the Size for the Array:");

scanf("%d",&size);

int*arr = (int*)malloc(sizeof(int)*size);

store(size,arr);

display(size,arr);

prime(size,arr);

void store(int size,int*arr){

prin ("\nEnter the Elements of the Array:\n");


int i;

for(i=0;i<size;i++) scanf("%d",&arr[i]);

void display(int size,int*arr){

int i;

prin ("The elements of Array are: ");

for(i=0;i<size;i++) prin ("%d ",arr[i]);

void prime(int size,int*arr){

int i,j;

prin ("\nThe Prime numbers of Array are: ");

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

for(j=2;j<=(arr[i]/2);j++){

if(arr[i]%j == 0) break;

if(j == ((arr[i]/2) + 1)) prin ("%d ",arr[i]);

Q7)

#include<stdio.h>

void store(int,int*);

void display(int,int*);

void sum(int,int*,int*,int*);

void main(){

int size;

prin ("Enter the Size for the Array:");

scanf("%d",&size);

int*arr1 = (int*)malloc(sizeof(int)*size);

int*arr2 = (int*)malloc(sizeof(int)*size);

int*arr3 = (int*)malloc(sizeof(int)*size);

store(size,arr1);
display(size,arr1);

store(size,arr2);

display(size,arr2);

sum(size,arr1,arr2,arr3);

void store(int size,int*arr){

prin ("\nEnter the Elements of the Array:\n");

int i;

for(i=0;i<size;i++) scanf("%d",&arr[i]);

void display(int size,int*arr){

int i;

prin ("The elements of Array are: ");

for(i=0;i<size;i++) prin ("%d ",arr[i]);

void sum(int size,int*arr1,int*arr2,int*arr3){

int i;

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

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

prin ("\nThe elements of the final Array are: ");

for(i=0;i<size;i++) prin ("%d ",arr3[i]);

Q8)

#include<stdio.h>

void store(int,int*);

void display(int,int*);

void merge(int,int,int*,int*,int*);

void main(){

int size1;

prin ("Enter the Size for the First Array:");


scanf("%d",&size1);

int*arr1 = (int*)malloc(sizeof(int)*size1);

int size2;

store(size1,arr1);

display(size1,arr1);

prin ("\nEnter the Size for the Second Array:");

scanf("%d",&size2);

int*arr2 = (int*)malloc(sizeof(int)*size2);

store(size2,arr2);

display(size2,arr2);

int arr3[size1+size2];

merge(size1,size2,arr1,arr2,arr3);

void store(int size,int*arr){

prin ("\nEnter the Elements of the Array:\n");

int i;

for(i=0;i<size;i++) scanf("%d",&arr[i]);

void display(int size,int*arr){

int i;

prin ("The elements of Array are: ");

for(i=0;i<size;i++) prin ("%d ",arr[i]);

void merge(int size1,int size2,int*arr1,int*arr2,int*arr3){

int i;

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

arr3[i] = arr1[i];

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

arr3[size1+i] = arr2[i];

}
prin ("\nThe elements of the Merged Array are: ");

for(i=0;i<size1+size2;i++) prin ("%d ",arr3[i]);

Q9)

#include<stdio.h>

void main(){

int size;

prin ("Enter the Size for the Array:");

scanf("%d",&size);

int*arr = (int*)malloc(sizeof(int)*size);

store(size,arr);

display(size,arr);

reverse(size,arr);

void store(int size,int*arr){

prin ("\nEnter the Elements of the Array:\n");

int i;

for(i=0;i<size;i++) scanf("%d",&arr[i]);

void display(int size,int*arr){

int i;

prin ("The elements of Array are: ");

for(i=0;i<size;i++) prin ("%d ",arr[i]);

void reverse(int size,int*arr){

int i;

for(i=0;i<(size/2);i++){

int temp = arr[i];

arr[i] = arr[size-1-i];

arr[size-i-1] = temp;

}
prin ("\nThe elements of Reversed Array are: ");

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

prin ("%d ",arr[i]);

Q10)

#include<stdio.h>

void main(){

int size;

prin ("Enter the Size for the Array:");

scanf("%d",&size);

int*ptr = (int*)malloc(sizeof(int)*size);

store(size,ptr);

display(size,ptr);

sort(size,ptr);

void store(int size,int*arr){

prin ("\nEnter the Elements of the Array:\n");

int i;

for(i=0;i<size;i++) scanf("%d",&arr[i]);

void display(int size,int*arr){

int i;

prin ("The elements of Array are: ");

for(i=0;i<size;i++) prin ("%d ",arr[i]);

void sort(int size,int*arr){

int i,j;

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

for(j=i+1;j<size;j++){

if(arr[i] > arr[j]){

int temp = arr[i];


arr[i] = arr[j];

arr[j] = temp;

prin ("\nThe elements of Sorted Array are: ");

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

prin ("%d ",arr[i]);

You might also like