Addition of Arrays C program

This C program accepts a 2-dim array of size 4*4 and prints the addition of all elements in individual columns. And print the result as below:
p q r s
p q r s
p q r s
p q r s
4p 4q 4r 4s
This is a part of Mumbai University MCA Colleges C programs MCA Sem 1


#include<stdio.h>
#include<conio.h>
void main()
{
int a[4][4],i,j,s[4]={0,0,0,0};
clrscr();
printf("\nEnter values for 2D array\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{scanf("%d",&a[i][j]);}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf("%d ",a[i][j]);
s[j]=s[j]+a[i][j];
}
printf("\n");
}
printf("-------------------\n");
for(j=0;j<4;j++)
{
printf("%d ",s[j]);
}
getch();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

No comments:

Post a Comment