need help to convert C++ to C. Can you please includethe function of each import
ID: 3610373 • Letter: N
Question
need help to convert C++ to C. Can you please includethe function of each important code in thecomment.#include<iostream>
using namespace std;
void perfect(int num){
int sum=0;
for(int i=1; i<num; i++)
{
if( (num % i) ==0) //a number i is a factor ofa number num
{ //if i divides into num with no remainder
sum +=i; //if its a factor add it with the otherfactors
}
}
if(sum ==num) //if the sum of the factors is num
{
cout<<num<<""<<endl; //itis perfect
}
return;
}
int main(){
int input;
cout<<"The perfect numbers between 1 and10000 are: ";
for(input=1;input<=10000;input++)
perfect(input);
system("pause");
return 0;
}
Explanation / Answer
#include<stdio.h>
#include<conio.h>
void perfect(int num){
int sum=0;
for(int i=1; i<num; i++)
{
if( (num % i) ==0) //a number i is a factor ofa number num
{ //if i divides into num with no remainder
sum +=i; //if its a factor add it with the otherfactors
}
}
if(sum ==num) //if the sum of the factors is num
{
printf("%d ",num); //it is perfect
}
return;
}
int main(){
intinput;
printf("The perfect numbers between 1 and 10000are: ");
for(input=1;input<=10000;input++)
perfect(input);
getch();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.