0

What is wrong here

for(i; i!=0; i=i){ if((i%p)==0){ cout<<p<<"×"; i=i/p; } else {p++;}

16th Apr 2018, 2:45 AM
Link Skwor
Link Skwor - avatar
2 ответов
+ 1
Well it's showing odd results. https://code.sololearn.com/c8J4dzZZfr1L/?ref=app I might have your code's logic. The mistake that you made was to put an else() statement outside of the {} braces of the for() loop. updated code: for(i; i!=0; i=i){ if((i%p)==0){ cout<<p<<"×"; i=i/p; else {p++;} }
16th Apr 2018, 2:59 AM
Rahul George
Rahul George - avatar
0
/*this is the whole code. I made some changes. now it works, Thanks.*\ #include<iostream> #include<math.h> using namespace std; int main(){ int i,p=2,n=0,c; cout<<"numero para extraer descomposicion factorial: ";cin>>i; c=i; while(i!=1){ n=i%p; if(n==0){ cout<<p<<"×"; i=i/p; } else {p++;} } cout<<"1= "<<c; return 0; }
16th Apr 2018, 3:09 AM
Link Skwor
Link Skwor - avatar