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

array-1

The document contains multiple C programs demonstrating various operations on arrays, including input/output operations, calculating the sum of even elements, performing linear search, finding minimum and maximum values, reversing array elements, and appending one array to another. Each program prompts the user for input and displays the results accordingly. The examples illustrate fundamental array manipulations in C programming.

Uploaded by

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

array-1

The document contains multiple C programs demonstrating various operations on arrays, including input/output operations, calculating the sum of even elements, performing linear search, finding minimum and maximum values, reversing array elements, and appending one array to another. Each program prompts the user for input and displays the results accordingly. The examples illustrate fundamental array manipulations in C programming.

Uploaded by

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

Input output operation with array:

#include<stdio.h>

int main()

int a[5],i;

printf("enter elements of the array");

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

printf("enter data");

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

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

printf("\n%d",a[i]);

return 0;

Sum of even elements:

#include<stdio.h>

int main()

int a[5],i,sum=0;
printf("enter elements of the array");

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

printf("enter data");

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

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

if(a[i]%2==0)

sum=sum+a[i];

printf("\n%d",sum);

return 0;

Linear search:

#include<stdio.h>

int main()

int a[5],i,n,flag=0;

printf("enter elements of the array");

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

{
printf("enter data");

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

printf("enter data to be searched for");

scanf("%d",&n);

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

if(a[i]==n)

flag=1;

break;

if(flag==1)

printf("item found");

else

printf("item not found");

return 0;

Minimum and maximum:

#include<stdio.h>
int main()

int a[5],i,max,min;

printf("enter elements of the array");

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

printf("enter data");

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

max=a[0];

for(i=1;i<5;i++)

if(max<a[i])

max=a[i];

printf("maximum element is=%d",max);

min=a[0];

for(i=1;i<5;i++)

if(min>a[i])

min=a[i];

printf("minimum element is=%d",min);


return 0;

Reversing array elements:

#include<stdio.h>

int main()

int a[5],i,j,temp;

printf("enter elements of the array");

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

printf("enter data");

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

for(i=0,j=4;i<=j;i++,j--)

temp=a[i];

a[i]=a[j];

a[j]=temp;

}
printf("\nafter reversing elements");

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

printf("\n%d",a[i]);

return 0;

Append array in another array:

#include<stdio.h>

int main()

int a[50],b[50],i,j,n,m;

printf("\nhow many elements in the 1st array");

scanf("%d",&n);

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

printf("enter data");

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

printf("\nhow many elements in the 2nd array");

scanf("%d",&m);
for(i=0;i<m;i++)

printf("enter data");

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

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

a[i]=b[j];

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

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

return 0;

You might also like