Answer:
Written in Python
for num in range(1,1001):
sum=0
for j in range(1,num+1):
if num%j==0:
sum = sum + j
if num == sum:
print(str(num)+" is a perfect number")
Explanation:
This line gets the range from 1 to 1000
for num in range(1,1001):
This line initializes sum to 0 for each number 1 to 1000
sum=0
This line gets the divisor for each number 1 to 1000
for j in range(1,num+1):
This following if condition line checks for divisor of each number
<em> if num%j==0:
</em>
<em> sum = sum + j
</em>
The following if condition checks for perfect number
if num == sum:
print(str(num)+" is a perfect number")
Answer:
#include <iostream>
using namespace std;
void filterEvens(int myArray[]) {
for (int i = 0; i < 8; ++i) {
if(myArray[i]%2==0){
cout<<myArray[i]<<" ";
}
}
}
int main(){
int myArray[8];
for(int i =0;i<8;i++){
cin>>myArray[i];
}
filterEvens(myArray);
return 0;
}
Explanation:
The solution is provided in C++
#include <iostream>
using namespace std;
The function filerEvens is defined here
void filterEvens(int myArray[]) {
This iterates through the elements of the array
for (int i = 0; i < 8; ++i) {
This checks if current element is an even number
if(myArray[i]%2==0){
If yes, this prints the array element
cout<<myArray[i]<<" ";
}
}
}
The main begins here
int main(){
This declares an integer array of 8 elements
int myArray[8];
The following iteration allows input into the array
<em> for(int i =0;i<8;i++){</em>
<em> cin>>myArray[i];</em>
<em> }</em>
This calls the defined function filter Evens
filterEvens(myArray);
return 0;
}
<span>first make a text file, then write the framework or(scripts for your program). Then write Your Instruction and save Your Program. After you've done that, get and install java jdk(its like a development tool). Finally c<span>opy the path(text file) to the Java tools(jdk)
</span></span>