- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C++ program to find perfect array of size n whose subarray is a good array

Suppose we have a number n. An array B is good if the sum of its elements is divisible by the length of this array. We can say an array A with n elements is perfect, if non-empty subarray of this array A is good and elements in A is in range 1 to 100. From the number n, we have to find an array A which is perfect.

So, if the input is like n = 4, then the output will be [7, 37, 79, 49], other answers are also possible.

## Steps

To solve this, we will follow these steps −

for initialize i := 0, when i < n, update (increase i by 1), do: print 1

## Example

Let us see the following implementation to get better understanding −

#include<bits/stdc++.h> using namespace std; void solve(int n){ for(int i=0;i<n;i++){ cout<<"1"<<", "; } } int main(){ int n = 4; solve(n); }

## Input

4

## Output

1, 1, 1, 1,

- Related Articles
- Count of pairs in an array whose sum is a perfect square in C++
- Program to find maximum score of a good subarray in Python
- C Program to find sum of perfect square elements in an array using pointers.
- C++ program to find reduced size of the array after removal operations
- Program to find array of length k from given array whose unfairness is minimum in python
- Find mean of subarray means in a given array in C++
- Find the only repeating element in a sorted array of size n using C++
- C/C++ Program to Find reminder of array multiplication divided by n ?
- Write a Java program to find the first array element whose value is repeated an integer array?
- C++ Program to find Number Whose XOR Sum with Given Array is a Given Number k
- C/C++ Program to Find the reminder of array multiplication divided by n?
- Find element in a sorted array whose frequency is greater than or equal to n/2 in C++.
- C++ Program to get the subarray from an array using a specified range of indices
- C program to add all perfect square elements in an array.
- Find if array has an element whose value is half of array sum in C++

Advertisements