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

Assignment 7

Uploaded by

vrunurade
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Assignment 7

Uploaded by

vrunurade
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Q1)

#include<stdio.h>

void main(){

int size;

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

scanf("%d",&size);

int arr[size];

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

int i;

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

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

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

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

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>

void main(){

int size;

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

scanf("%d",&size);

int arr[size];

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

int i;

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

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


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

int key;

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

scanf("%d",&key);

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

if(key == arr[i]){

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

break;

if(i == size) prin ("The element %d is not present in the array.",key);

Q3)

#include<stdio.h>

void main(){

int size;

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

scanf("%d",&size);

int arr[size];

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

int i;

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

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

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

int sum = 0;

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

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

Q4)

#include<stdio.h>

void main(){
int size;

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

scanf("%d",&size);

int arr[size];

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

int i;

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

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

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

prin ("The Even Numbers in the Array are: ")

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

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

prin ("The 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 main(){

int size;

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

scanf("%d",&size);

int arr[size];

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

int i;

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

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

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

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


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

Q6)

#include<stdio.h>

void main(){

int size;

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

scanf("%d",&size);

int arr[size];

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

int i,j;

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

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

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

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 main(){

int size;

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

scanf("%d",&size);

int arr1[size];

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

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

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

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

int arr2[size];

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

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

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

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

int arr3[size];

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 main(){

int size1;

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

scanf("%d",&size1);

int arr1[size1];

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

int i;

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

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

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

int size2;

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

scanf("%d",&size2);

int arr2[size2];
prin ("\nEnter the Elements of the Second Array:\n");

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

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

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

int arr3[size1+size2];

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,i,arr[size];

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

scanf("%d",&size);

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

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

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

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

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

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

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

int temp = arr[i];

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

arr[size-i-1] = temp;

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

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

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

Q10)

#include<stdio.h>

void main(){

int size,arr[size],i,j;

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

scanf("%d",&size);

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

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

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

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

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

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

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