Witam
Na poczatku chcialbym podziekowac panu Mirosawowi za ogromna pomoc ;)
przejde teraz do pytania mam problem z cwiczeniem na petlach w C ,pytanie brzmi :
Write a program that reads a number from the keyboard, separates it into its individual digits and prints
the digits to screen, each on its own line followed by the same number of stars as itself.
Example:
Input:
2339
Output:
9 *********
3 ***
3 ***
2 **
Hint: make use of mathematical operations (division, modulus). Yes, you will end up with digits in reverse
order, that is expected.
a to co udalo mi sie rozwiazac:
#include<stdio.h>
#include<conio.h>
int main () {
int n , i = 0 ;
int digit ;
printf(" Number=");
scanf("%d",&n); // ask user for number
while (digit = n % 10 ) {
printf("\n%d",digit); // modules the user number to extract and print digit
while ( i++ < digit){ // print " * " equal to number of digit
printf("*");
while ( --digit)
printf("*");
}
// divide number to get modules from next number
n = n /10 ;
}
getch ();
return 0 ;
}
Czasem wyswieltja sie tylko 3/4 cyfr z gwiadkami , a czasami co druga cyfra pokazuje odpowiednia ilosc gwiazdek .Ma ktos pomysl jak to rozwiklac ? ;)
z Gory dziekuje za kazda pomoc.
Milego dnia ;)