Sunday, August 5, 2012
Array programming Write a C Program to fill up an Integer Array. The length of the array must take from the terminal. After fill up the array do the following operations. i) Print the array with label formatting. ii) Count the number of values inside the array. iii) Count the number of odd values. iv) Count the number of even values. v) Sum all the odd values. vi) Sum all the even values. vii) Calculate the average. viii) Find the largest value. ix) Find the smallest value.
#include
main()
{
int i, a[10],value,digit=0,sum=0,sum1=0,sum2=0,avg=0,max=0,min=32678;
printf("Enter your integer value:\n");
for(i=0;i<10;i++)
{
scanf("%d",&value);
a[i]=value;
printf("[%d]=%d\n",i,a[i]);
}
for(i=0;i<10;i++)
{
digit++;
}
printf("\n Total number:%d",digit);
for(i=0;i<10;i++)
{
if(a[i]%2==0)
{
printf("\n\n Even numbers:%d",a[i]);
}
}
for(i=0;i<10;i++)
{
if(a[i]%2!=0)
{
printf("\n\n Odd numbers:%d",a[i]);
}
}
for(i=0;i<10;i++)
{
if(a[i]%2==0)
{
sum1+=a[i];
}
}
printf("\nSum of even number:%d",sum1);
for(i=0;i<10;i++)
{
if(a[i]%2!=0)
{
sum2+=a[i];
}
}
printf("\n sum of Odd number:%d",sum2);
for(i=0;i<10;i++)
{
sum+=a[i];
}
(float)avg=sum/10;
printf("\navg=%d",avg);
for(i=0;i<10;i++)
{
if(a[i]>max)
{
max=a[i];
}
}
printf("\n maximum:%d",max);
for(i=0;i<10;i++)
{
if(a[i]
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.