Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Да се направи програма за факторизација на природен број n. Факторизација на природен
- број е постапка на претставување на бројот како производ од прости фактори, т.е производ
- од сите прости броеви на некој степен.
- */
- #include <stdio.h>
- int prost(int x) {
- int i;
- for (i=2; i<=x/2; i++) {
- if (x%i == 0) {
- return 0;
- }
- }
- return 1;
- }
- int main() {
- int broj;
- int i,del,stepen;
- printf("Vnesi broj: ");
- scanf("%d", &broj);
- printf("\n\n%d = ", broj);
- for (i=2; i<=broj; i++) {
- stepen = 0;
- if (prost(i) == 1) {
- while (broj%i == 0) {
- stepen++;
- broj /= i;
- }
- if (stepen != 0) {
- printf("%d^%d * ", i, stepen);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment