0% found this document useful (0 votes)
14 views9 pages

DS1 1

This document contains 6 C programming assignments submitted by student Tukaram Tadmadge: 1. A program to traverse an array by inputting elements and printing them. 2. A program to find the minimum element from an array of 5 numbers. 3. A program to sort 5 input numbers in ascending order. 4. A program to insert an element into an array at a specified position. 5. A program to delete an element from an array at a specified position. 6. A program to reverse the elements of an array.

Uploaded by

reddy gaming
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)
14 views9 pages

DS1 1

This document contains 6 C programming assignments submitted by student Tukaram Tadmadge: 1. A program to traverse an array by inputting elements and printing them. 2. A program to find the minimum element from an array of 5 numbers. 3. A program to sort 5 input numbers in ascending order. 4. A program to insert an element into an array at a specified position. 5. A program to delete an element from an array at a specified position. 6. A program to reverse the elements of an array.

Uploaded by

reddy gaming
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/ 9

ASSIGNMENT NO.

Name: TUKARAM TADMADGE


Roll no.256 Div: B
1. C program for array traversal.

//Traversing of array

#include<stdio.h
> int main()
{ int
a[5],i;

printf("Enter five
elements:");

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

printf("Array elements
are:\n");
for(i=0;i<5;i++) {
printf("%d\t",a[i]);
}
return 0;
}

Department of Computer Science And Engineering DYPCET


2. C program for finding minimum from 5 numbers.

//Min number

#include<stdio.h
> int main()
{
int

a[5],i,min;

printf("Ente

r 5

elements:");

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

min=a[0];
for(i=0;i<5;i++) {
if(min>a[i]) {
min=a[i]; } }
printf("Minimum
element is %d\n",min);
return 0;
}
3. C program for sorting given 5 numbers.

//sorting

#include<stdio.h
> int main()
{
int a[5],i,j,temp;
printf("Enter 5
elements:");
for(i=0;i<5;i++)

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

for(i=0;i<5;i++) {
for(j=i+1;j<5;j++)
{
if(a[i]>a[
j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("Sorted elements are:");
for(i=0;i<5;i++)
{
printf("%d\n",a[
i]); } return 0;
}
4. C program for inserting element in array at specified position.

// Insertion

#include<stdio.h>
int main()
{
int a[10],i,p,n,data;

printf("Enter size of

array:"); scanf("%d",

&n);

printf("Enter array
elements:");
for(i=0;i<n;i++) {
scanf("%d",&a[i]); }

printf("Enter element and position to insert an element:\n");


scanf("%d%d",&data,
&p); if(p>n || p<0) {
printf("Data can not be stored\n");
}
else{
n=n+1;
for(i=n-1;i>=p; i--) {
a[i+1]=a[i]; a[p-
1]=data;

}
printf("\nArray after
insertion:\n");
for(i=0;i<n;i++) {
printf("%d\n",a[i]); }

return 0;
}

5. C program for deleting element from array at specified position.

//deletion

#include<stdio.h>
int main()
{
int a[10],i,p,n,k;
printf("Enter the size of

array:");

scanf("%d", &n);

printf("Enter array elements:");


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

printf("Enter position to delete:\n");


scanf("%d",&p);

k=p-1;
if(p<=0 ||
p>=n)
{

printf("Invalid\n");

else{ for(i=k;i<n-
1;i++) {
a[i]=a[i+1]; }

printf("Array after deletion:\n");

for(i=0;i<n-1;i++) {
printf("%d\t",a[i]); }
return 0;
}
6. C program form reversing array elements.

//reversing array
#include<stdio.h
> int main()
{
int a[10],i,j,n,temp;

printf("Enter size of

array:"); scanf("%d",

&n);

printf("Enter array elements:");


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

for(i=0,j=n-1;i<n/2;i++,j--
) { temp=a[i]; a[i]=a[j];
a[j]=temp; } printf("Array
after riversing:\n");

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

You might also like