#include <iostream>
using namespace std;
 
void fill(int* v, int c)
{
    for (int i = 0; i < 10; i++)
        v[i] = c;
}
 
void add(int* v, int* x, int * y)
{
    for (int i = 0; i < 10; i++)
        v[i] = x[i] + y[i];
}
 
void print(int* v)
{
    cout << "[";
    for (int i = 0; i < 10; i++)
        cout << v[i] << ", ";
    cout << "]" << endl;
}
 
int a[10];
int b[10];
int c[10];
 
int main()
{
    fill(a, 10);
    fill(b, 20);
    add(c, a, b); // c[i] = a[i] + b[i] pro i = 0...9 
    print(c);
}
#include <iostream>
#include <stdlib.h>
using namespace std;
 
void fill(int* v, int s, int c)
{
    for (int i = 0; i < s; i++)
        v[i] = c;
}
 
void add(int* v, int* x, int * y, int s)
{
    for (int i = 0; i < s; i++)
        v[i] = x[i] + y[i];
}
 
void print(int* v, int s)
{
    cout << "[";
    for (int i = 0; i < s; i++)
        cout << v[i] << ", ";
    cout << "]" << endl;
}
 
int main()
{
    int s = 20;
    int* a = new int[s];
    int* b = (int *) malloc (s * sizeof (int));
    int* c = new int[s];
 
    fill(a, s, 10);
    fill(b, s, 20);
    add(c, a, b, s); // c[i] = a[i] + b[i] pro i = 0...9 
    print(c, s);
}
 
cpole2019.txt · Last modified: 2019/12/03 13:11 by 147.32.8.110
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki