10.GOLD trick(Mars Trickery)
19 May 2020 | STL Programming Practice_1
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int A[8];
void add(int front_, int backend_, int x)
{
for (front_;front_<=backend_;front_++)
{
A[front_-1]+=x;
}
}
void print()
{
int n = sizeof(A)/sizeof(A[0]);
for(int i = 0 ; i<=n; i++)
{
cout<<A[i]<<" ";
}
cout<<"\n";
}
int main()
{
add(3,6,5);
print();
add(1,4,10);
print();
add(5,8,10);
print();
return 0;
}
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int A[8];
void add(int front_, int backend_, int x)
{
for (front_;front_<=backend_;front_++)
{
A[front_-1]+=x;
}
}
void print()
{
int n = sizeof(A)/sizeof(A[0]);
for(int i = 0 ; i<=n; i++)
{
cout<<A[i]<<" ";
}
cout<<"\n";
}
int main()
{
add(3,6,5);
print();
add(1,4,10);
print();
add(5,8,10);
print();
return 0;
}
Comments