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

Assignment On Array

This document contains 4 programming assignments for a structured programming language course. Each assignment asks the student to write a C program to perform an operation on arrays: 1) Separate odd and even integers into separate arrays, 2) Sort elements of an array in ascending order, 3) Delete an element from a desired position in an array, 4) Find the second largest element in an array. The document provides the assignment details and the student's submitted solutions to each programming problem in C code.

Uploaded by

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

Assignment On Array

This document contains 4 programming assignments for a structured programming language course. Each assignment asks the student to write a C program to perform an operation on arrays: 1) Separate odd and even integers into separate arrays, 2) Sort elements of an array in ascending order, 3) Delete an element from a desired position in an array, 4) Find the second largest element in an array. The document provides the assignment details and the student's submitted solutions to each programming problem in C code.

Uploaded by

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

BANGABANDHU SEIKH MUJIBUR

RAHMAN DIGITAL UNIVERSITY,


Kaliakair,Gazipur.

Assignment:
Course No: PROG-102
Course Title: Structured Programming
Language (sessional)
Assignment On: Array

Submitted By: Submitted to:


Name: Suwaybid Ahmmed Md. Moshiur Rahman,
Muaz Lecturer,
Id: 2201020 Depertment of IRE,
Depertment : Internet of Bangabandhu Seikh Mujibur
Things and Robotics Rahman Digital University
Engineering
Session : 2022-2023
1. Write a program in C to separate odd and even
integers into separate arrays

#include<stdio.h>

#define Size 6

int main() {

int arr[Size],even[Size],odd[Size];

int I; int oddcount=0,evencount=0;

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

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

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

if(arr[i]%2==0){

even[evencount]=arr[i];

evencount++; }

else{ odd[oddcount]=arr[i]; oddc++; } }

printf("\n");

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

{ printf("Even Number:%d\n",even[i]); }

printf("\n");

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

{ printf("odd Number:%d\n",odd[i]); }

return 0; }
2. Write a program in C to sort elements of an array in
ascending order

#include<stdio.h>

int main(){

int a[5]; int m, n, temp;

for(i=0;i<5;i++) { scanf("%d",&a[m]); }

printf("elements are:\n");

for(i=0;i<5;i++) { printf("%d\n",a[m]); }

for(i=0;i<5;i++) { for(n=i+1;j<5;n++) { if(a[m]<a[n])

{ temp=a[m];

a[m]=a[n];

a[n]=temp;

} } }

printf("ascendric order order:\n");

for(i=0;i<5;i++) { printf("%d\n",a[m]); }

return 0; }
3. Write a program in C to delete an element at a desired
position from an array

#include <stdio.h>

#define MAX_SIZE 100

int main() {

int arr[MAX_SIZE]; int i, size, pos;

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

scanf("%d", &size);

printf("Enter elements in array : ");

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

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

printf("Enter the element position to delete : ");

scanf("%d", &pos);

if(pos < 0 || pos > size)

{ printf("Invalid position! Please enter position between 1 to %d", size); }

else { for(i=pos-1; i<size-1; i++)

{ arr[i] = arr[i + 1]; }

size--;

printf("\nElements of array after delete are : ");

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

{ printf("%d\t", arr[i]); } }

return 0; }
4. Write a program in C to find the second largest
element in an array
#include<stdio.h>
#define size 6
int main()
{
int i,max,max2=0;
int a[size];
for(i=0;i<size;i++) { scanf("%d",&a[i]); }
max=a[i];
for(i=0;i<size;i++) { if(a[i]>max) { max2=max; max=a[i]; }
else if(a[i]>max2 && a[i]<max){ max2=a[i]; } }
printf("\n");
printf("second highest:%d\n\n",max2);
return 0;
}

You might also like