IHYPRESS.NET
C
HOME | ASP | C | CSS | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
COne Dimensional Arrays ❯ Adding Two Arrays
<07.07>
/* 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); }
Hergestellt in Deutschland / Made in Germany
1 2 3 4 + 10 20 30 40 ------------- 11 22 33 44
COPYRIGHT © 2015-2024 IHYPRESS.NET. A DIVISION OF IHY PRESS. ALL RIGHTS RESERVED.