Skip to content

Commit cfa4132

Browse files
committed
solve productArrayPuzzle
1 parent 86b6b92 commit cfa4132

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
/*******************************************************************************************************
3+
/* ___ _ _ _ _
4+
/* / _ \ | | (_)| | | |
5+
/* / /_\ \__ __ ___ | | __ _ ___ _ __ _ | |_ | |__ _ __ ___ ___
6+
/* | _ |\ \ /\ / / / _ \| | / _` | / _ \ | '__|| || __|| '_ \ | '_ ` _ \ / __|
7+
/* | | | | \ V V / | __/| || (_| || (_) || | | || |_ | | | || | | | | |\__ \
8+
/* \_| |_/ \_/\_/ \___||_| \__, | \___/ |_| |_| \__||_| |_||_| |_| |_||___/
9+
/* __/ |
10+
/* |___/
11+
/******************************************************************************************************/
12+
13+
/***********************************
14+
/* Reverse An Array
15+
/***********************************/
16+
17+
// Library imports
18+
#include <iostream>
19+
using namespace std;
20+
21+
//Prototypes for the algorithms
22+
int productArrayPuzzle(int* arr,int len);
23+
24+
int main(){
25+
// Lines to handle user input go here, be descriptive...
26+
// use cin, cout
27+
int arr[] = {10, 3, 5, 6, 2};
28+
int arrayLength = sizeof(arr)/sizeof(arr[0]);
29+
// Call your algorithms here
30+
productArrayPuzzle(arr, arrayLength);
31+
32+
33+
34+
return 0;
35+
}
36+
37+
/**********************************************************
38+
/* <productArrayPuzzle>
39+
/*
40+
/* @description : description here
41+
/* @param : Integer<variable> (Datatype<variable_name>)
42+
/* @return : datatype (int,float,double etc)
43+
/* @complexity : Big O notation. (O(n),O(n^2) etc)
44+
/* @explanation : Detailed description about what the algorithm does
45+
/* @author : <Your name> @<GitHub handle> (John Doe @johndoe)
46+
/**********************************************************/
47+
int productArrayPuzzle(int* arr,int len){ //simple one first
48+
// Algorithm content goes here.
49+
50+
int product =1;
51+
52+
for(int i=0;i<len;i++){
53+
product *= arr[i];
54+
}
55+
56+
for(int i=0;i<len;i++){
57+
arr[i] = product/arr[i];
58+
59+
cout<<arr[i]<<endl;
60+
}
61+
}

Arrays and Strings/C++/test

-8.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)