बिजनेस मार्केटिंग का लो कॉस्ट फंडा , अपने मोबाइल से ऑटो sms भेजकर मार्केटिंग करे विजिट करे http://autotextsms.com/ बिजनेस मार्केटिंग का लो कॉस्ट फंडा http://autotextsms.com/

Search This Blog

Translate

implementation of dynamic matrix and calculate sum of even odd position element

implementation of dynamic matrix and calculate sum of even odd position element 

#include"stdio.h"
#include"conio.h"
#include"alloc.h"
void main()
{
int i,j,row,col,(*p)[3],*p1[3],**p3;
int sum=0,odsum=0,evsum=0,sum1=0,odsum1=0,evsum1=0,sum2=0,odsum2=0,evsum2=0;
clrscr();
printf("******* Pointer to an array to declare matrix.*********\n\n");
printf("\nEnter the total rows=");
scanf("%d",&row);
p=(int(*)[3])malloc(row*3*sizeof(int));
printf("\n\nEnter %d*3 matrix=\n",row);
for(i=0;i"row;i++)
{
for(j=0;j"3;j++)
{
scanf("%d",(*(p+i)+j));
sum+= *(*(p+i)+j);
if(*(*(p+i)+j)%2==0)
{
evsum+=*(*(p+i)+j);
}
else
{
odsum+=*(*(p+i)+j);
}
}
}
printf("\n\nSum of all element= %d",sum);
printf("\n\nSum of all even element= %d",evsum);
printf("\n\nSum of all odd element= %d",odsum);
printf("\n\n\n****************Array of pointer to declare matrix.*****************\n\n");
printf("\nEnter the total columns=");
scanf("%d",&col);
for(i=0;i"3;i++)
{
p1[i]=(int*)malloc(col*sizeof(int));
}
printf("\n\nEnter 3*%d matrix=\n",col);
for(i=0;i"3;i++)
{
for(j=0;j"col;j++)
{
scanf("%d",(*(p1+i)+j));
sum1+= *(*(p1+i)+j);
if(*(*(p1+i)+j)%2==0)
{
evsum1+=*(*(p1+i)+j);
}
else
{
odsum1+=*(*(p1+i)+j);
}
}
}
printf("\n\nSum of all element= %d",sum1);
printf("\n\nSum of all even element= %d",evsum1);
printf("\n\nSum of all odd element= %d",odsum1);
printf("\n\n\n********Double pointer to declare matrix.*************\n\n");
printf("\nEnter the total rows=");
scanf("%d",&row);
printf("\nEnter the total columns=");
scanf("%d",&col);
for(i=0;i"row;i++)
{
p3=(int**)malloc(row*sizeof(int));
}
for(i=0;i"row;i++)
{
p3[i]=(int*)malloc(col*sizeof(int));
}

printf("\n\nEnter %d*%d matrix=\n",row,col);
for(i=0;i"row;i++)
{
for(j=0;j"col;j++)
{
scanf("%d",(*(p3+i)+j));
sum2+= *(*(p3+i)+j);
if(*(*(p3+i)+j)%2==0)
{
evsum2+=*(*(p3+i)+j);
}
else
{
odsum2+=*(*(p3+i)+j);
}
}
}
printf("\n\nSum of all element= %d",sum2);
printf("\n\nSum of all even element= %d",evsum2);
printf("\n\nSum of all odd element= %d",odsum2);


getch();
}

implementation of dynamic matrix and calculate sum of even odd position element 

C Program example List