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.

Recommended Answers

All 8 Replies

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.

I mean ... Who can "check" my syntax ..
Sorry about that.
Thanks. :)

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? Thanks :)

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.

Okay. Thanks. I'll try to make another one. Thanks Narue.

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

The line for (R==2; R>N; R++) should be for (R=2; R<N; R++) , but that's the least of your problems... Anyway, here is the wikipedia article on the subject which may help you understand the problem better: http://en.wikipedia.org/wiki/Prime_factorization

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.