Array : Adding Two Arrays
/* Problem: Add the corresponding values from two arrays of the same size. */ #include <stdio.h> /* the function that adds the two arrays a1 and a2. it "returns" a3 back */ void addarrays (int a1[], int a2[], int a3[], int n) { int i; /* do the adding of every corresponding cells */ for (i=0; i<n; ++i) a3[i] = a1[i] + a2[i]; } int main (void) { int x[] = {1,2,3,4}, i; int y[] = {10,20,30,40}; int z[4]; /* call the function */ addarrays (x, y, z, 4); /* print a report */ for (i=0; i<4; ++i) printf ("%3d", x[i]); printf ("\n + \n"); for (i=0; i<4; ++i) printf ("%3d", y[i]); printf ("\n-------------\n"); for (i=0; i<4; ++i) printf ("%3d", z[i]); return (0); }
//Add the corresponding values from two arrays of the same size.
ReplyDeleteinclude(stdio.h)
void add (int a1[],int a2[],int a3[],int n)
{
int i=0;
while(i<n)
{
a3[i]=a1[i]+a2[i];
i++;
}
}
int main(void)
{
int x[4]={99,6,55,36},i=0;
int y[4]={12,1,44,30};
int z[4];
add(x,y,z,4);
while(i<4)
{
printf("%4d",x[i]);
i++;
}
printf("\n+\n");
i=0;
while(i<4)
{
printf("%4d",y[i]);
i++;
}
printf("\n-----------------\n");
i=0;
while(i<4)
{
printf("%4d",z[i]);
i++;
}
getch();
}
#include
ReplyDeletemain()
{
int a[4]={2,3,4,5};
int sum=0,i;
int b[4]={3,4,5,6};
for(i=0;i<4;i++)
{
sum=a[i]+b[i];
printf("%d\n",sum );
}
}
#include
ReplyDeleteusing namespace std;
int main()
{
int array[4]={2,3,4,5},array2[4]={4,6,2,8},i,sum=0;
for(i=0;i<4;i++)
{
sum=array[i]+array2[i];
cout<<sum<<endl;
}
}
#include
ReplyDeleteint main(){
int p[3]={1,2,3};
int q[3]={3,2,1};
int i,sum=0;
for(i=0;i<=3;i++)
{
sum+=p[i]+q[i];
printf("%d\n",sum);
}
}
#include
ReplyDeleteint main()
{
int sum=0,i,a[5]={1,2,3,4,5},b[3]={6,7,8};
for(i=0;i<3;i++)
{
sum=a[i]+b[i];
printf("\n%d",sum);
}
}
Name : Sumsunnahar Nawa
ReplyDeleteID : 201710090
Batch:54th
https://drive.google.com/open?id=1TMD0g81TcLL7Nvr67ThRz_gJeR6PdCXr
Shipon Hossan
ReplyDeleteID-201810009
https://drive.google.com/open?id=1XN2CHOa9H6isNsV_qestSHunf-TMHKsg
Dilruba Parvin Tonni
ReplyDeleteID-201810641
https://drive.google.com/open?id=1g_99AeL_Bh_6zEJ9j-sKllZJb0d9CtAB
Fazlul Haque Rana
ReplyDeleteID-201810233
https://drive.google.com/open?id=1OQ2IWscUD5_6sZB99JNSpPhYxdBEmFJA
ID: 201810037
ReplyDeletehttps://drive.google.com/open?id=1JKxVj5TS4_UsIdb7BfP07m2Lq9oMF7Fs
Shamima Islam Sima
ReplyDeleteID-201810532
https://drive.google.com/open?id=1QDvygS8_K0Pov5ry02yFwFLEpK81Bbdd
https://drive.google.com/open?id=1xnfg_-Rd3rQla4mjY4bsHMszOnIpKXVI
ReplyDeleteID: 201710404
ID #201610288
ReplyDeletehttps://drive.google.com/open?id=19FUFQCTJYnCXYl1XlVEsXGNo91cj5Am37wd4Y844WSU
ID #201611036
ReplyDeleteLink--> https://drive.google.com/open?id=1c0DGNcvG_2ZN0LZDKZcbPg3MEK034Mns
ID:201620318
ReplyDeletehttps://drive.google.com/open?id=1IV_dyPc9F9MPDrFo6tWOVr6MXUJ7LeBG