Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Primfaktorzerlegung

Empfohlene Antworten

Veröffentlicht

Hallo Leute,

ich soll ein C-Programm zur Primfaktorzerlegung schreiben, wobei das Programm nicht nur eine einzige Zahl zerlegen soll, sondern einen ganzen Zahlenbreich, der durch die Eingabe von 2 Ziffern gekenntzeichnet werden soll.

Leider klappt das bei mir nicht, das Programm zerlegt mir einfach immer nur den ersten Wert, weil ich es ehrlich gestanden nicht besser hinkriege, ich weiß einfach nicht was ich machen muss, damit es den ganzen Bereich zerlegt =(

Noch als Warnung, ich programmiere erst seit kurzem, also verzeiht falls was noch nicht richtig verschachtelt und deshalb unübersichtlich etc ist.....

Hier das bisherige Programm:

#include <stdio.h>

#include <math.h>

int main(){

int z1, z2;

int i;

int j;

printf("Bitte geben sie einen Zahlbereich mit Hilfe von 2 Ziffern an.\n\n");

printf("Geben sie die erste Zahl ein.\n");

scanf("%i", &z1);

printf("Geben sie die zweite Zahl ein.\n");

scanf("%i", &z2);

if (z1>z2)

{

printf("Ungueltige Eingabe!\n");

}

else

{

for(j=z1; j<=z2; j++)

{

i = 2;

int multiplikation = 0;

while (z1!= 1)

{

while ((z1%i != 0)&&(i<=z1))

{

i++;

}

if(multiplikation != 0)

printf("*");

if(i > z1)

{

printf("%d", z1);

z1 = 1;

break;

}

z1 = z1 / i;

printf("%i", i);

multiplikation = 1;

}

}

}

printf("\n");

return 0;

}

Ich wäre über jede Hilfe überaus dankbar, ich muss das bis morgen haben und wenn ich die ganze Nacht dran sitzen muss....

glg

PS: Ach ja, das Programm das nur eine Zahl zerlegt und funzt sieht im übrigen so aus, falls es denn was hilft:

#include <stdio.h>

#include <math.h>

int main (void){

int n,i;

printf("Geben sie eine natuerliche Zahl fuer die Primfaktorzerlegung ein.\n");

scanf("%d", &n);

if (n<=1)

{

printf("Die Zahl darf nicht kleiner gleich 1 sein!\n");

}

else

{

i = 2;

int multiplikation = 0;

while (n != 1)

{

while ((n%i != 0)&&(i<=n))

{

i++;

}

if(multiplikation != 0)

printf("*");

if(i > n)

{

printf("%d", n);

n = 1;

break;

}

n = n / i;

printf("%i", i);

multiplikation = 1;

}

}

printf("\n");

return 0;

}

Bearbeitet von freak13

:upps ähh ja das klingt jetzt irgendwie logisch :upps

Tausend Dank, das war wie ein Brett vor meinem Kopf!

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.