Program which does the below process after reading on odd no of integer - 100 Most Important C# Programs

100 Most Important C# Programs

72. Program which does the below process after reading on odd no of integer.

a)Print them in given order.

b)Replace second elements by product of first and last element

c)Replace middle value by average of all elements.

d)Replace all –ve no’s by zero’s.

Code:

#include<stdio.h>

#include<conio.h>

main( )

{

int a[10],i,n,sum=0;

clrscr( );

printf(“enter the array sixe “);

scanf(“%d”,&n);

printf(“enter the elements”);

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

{

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

sum=sum+a[i];

}

printf(“The given arrays is: “);

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

printf(“%d”,a[i]);

a[2]=a[1]*a[n-1];

printf(“\n the given areay after replacing

2nd element is”);

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

printf(“%d”,a[i]);

a[(1+n/2)]=sum/n;

printf(“\n the given array after replacing

middle element by average of all”);

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

if(a[i]<0)

a[i]=0;

printf(“\n given array after replacing –ve

values by zero”);

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

printf(“%d”,a[i]);

printf(“\n”);

getch();

}