Click here to Skip to main content
15,868,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include <iostream>
using namespace std;
	int main()
{
int d,n,e;
cout<<"n="; cin>>n;
d=2;
while (d*d<=n){
e=0;
while (n%d==0){
n=n/d;
e++;
}
if(e>0,d++) 
}
if (n>1) }


What I have tried:

I have many thing but can't get this thing to work.
Posted
Updated 9-Nov-22 21:15pm
Comments
TRansSky 10-Nov-22 2:40am    
Also I forgot to put what I intendet to do.
A non-zero natural number n is read from the keyboard, then n integer values are successively read. Write
a program to check if any number read has an odd number of divisors
receive

1 solution

First off, indent your code: it becomes a lot more readable:
C++
#include <iostream>
using namespace std;
int main(){
    int d,n,e;
    cout<<"n="; cin>>n;
    d=2;
    while (d*d<=n){
        e=0;
        while (n%d==0){
            n=n/d;
            e++;
            }
        if(e>0,d++) 
    }
    if (n>1) }
Now it is obvious that the code won't compile!
The format of an if statement is simple:
C++
if (condition)
   statement;
Or
C++
if (condition) {
   statement;
   statement;
   }
If the condition evaluates to true, the statement (or statements if a block is used) is executed. If it doesn't, they aren't.

Your code doesn't look like that:
C++
if(e>0,d++)
C++
if (n>1) }

So think about what exactly you are trying to do, and then think about the statement syntax.
You'll see what I mean.
 
Share this answer
 
Comments
CPallini 10-Nov-22 4:43am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900