Arrays
Arrays
#include<stdio.h>
main()
{
int a[10]={10,20,30,40};
int i;
printf("\nThe elements are\n");
for(i=0;i<4;i++)
printf("%d ",a[i]);
/*CompileTime Initialization*/
#include<stdio.h>
main()
{
int a[]={10,20,30,40};
int i;
printf("\nThe elements are\n");
for(i=0;i<4;i++)
printf("%d ",a[i]);
/*CompileTime Initialization*/
#include<stdio.h>
main()
{
int a[10];
int i;
a[0]=10;
a[1]=20;
a[2]=30;
a[3]=40;
printf("\nThe elements are\n");
for(i=0;i<4;i++)
printf("%d ",a[i]);
}
/*Runtime Initialization*/
#include<stdio.h>
main()
{
int a[10];
int i,n;
printf("Enter no.of elements: "); scanf("%d",&n);
#include<stdio.h>
main()
{
int a[10];
int i,n,ocount=0,osum=0,ecount=0,esum=0;
system("clear");
printf("Enter no.of elements: "); scanf("%d",&n);
printf("Enter elements: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nThe elements are\n");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
if( a[i]%2!=0 )
{
ocount++;
osum = osum+a[i];
}
else
{
ecount++;
esum = esum+a[i];
}
}
printf("\nOdd numbers count = %d\n",ocount);
printf("\nOdd numbers sum = %d\n",osum);
printf("\neven numbers count = %d\n",ecount);
printf("\neven numbers sum = %d\n",esum);
}
#include<stdio.h>
main()
{
int a[10];
int i,n,sum=0;
float avg;
system("clear");
printf("Enter no.of elements: "); scanf("%d",&n);
printf("Enter elements: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
}
/* Addition code */
if(m==p && n==q)
{
for(i=0;i<m;i++)
for(j=0;j<n;j++)
c[i][j]=a[i][j]+b[i][j];
/* Printing resultant matrix c */
printf("\n\nThe resultant matrix is
given as\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
printf("%d ",c[i][j]);
printf("\n");
}
}
else
printf("\nAddition is not possible");
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(a[i][j]>big)
{
big=a[i][j];
brp=i;bcp=j;
}
if(a[i][j]<small)
{
small=a[i][j];
srp=i;scp=j;
}
}
}
printf("The biggest element =
%d\n",big);
printf("The biggest element location at
a[%d,%d] = %d\n",brp,bcp,a[brp][bcp]);
printf("The smallest element =
%d\n",small);
printf("The smallest element location
at a[%d,%d] = %d\n",srp,scp,a[srp][scp]);
}