Can someone help me in building a syntax for this problem

Write a program that accepts a positive integer and gives its prime factorization that expresses the integer as a product of primes.

Here's one that I did:

#include<stdio.h>
#include<conio.h>
void main()
int N,R;
clrscr();
printf("Please enter a no.:\n");
scanf("%d",&N);
{ for(R==2;R>N;R++)
 if(N%R==0)
 printf("%d",R)
 else if(N%R!=0)
 printf("%d",N);
 else 
 printf("Invalid");
}
getch();
}

Thanks.

Can someone help me in building a syntax for this problem

Write a program that accepts a positive integer and gives its prime factorization that expresses the integer as a product of primes.

Here's one that I did:

#include<stdio.h>
#include<conio.h>    // remove, not needed
void main()          // main is NEVER void, it's int
int N,R;             // why aren't you indenting so we can follow this?
clrscr();            // Get rid of this annoying line
printf("Please enter a no.:\n");
scanf("%d",&N);
{ for(R==2;R>N;R++)
 if(N%R==0)
 printf("%d",R)
 else if(N%R!=0)
 printf("%d",N);
 else 
 printf("Invalid");
}
getch();             // Get rid of this, it's not standard. 
                     // Use something standard like getchar()
}

Other than that, what do you need help with? You need to ask a question that can be answered. "Can someone help?" doesn't give us any useful info to describe what you need help with.

The compiler. Press/click the build or run button and if your syntax is wrong, the compiler will tell you.

Can you suggest a better code for this?

Yes, but given past history, I suspect you'll continue to use your current awful code style even if somebody shows you a much better alternative. Thus, I'm inclined to think that suggesting better code for you would be a waste of time.

Edited 5 Years Ago by Narue: n/a

your code does n't seems to give right output..

for prime factorization you should search for sqrt(n) method, where n is number whose prime factorization is to be found

This article has been dead for over six months. Start a new discussion instead.