int length(unsigned int cislo){ //vrati delku cisla
int len=0;
while ((cislo/=10)!=0){
len++;
}
return len+1;
}
int maxlength(unsigned int cislo1, unsigned int cislo2){ //vrati delku delsiho cisla
int l1=length(cislo1);
int l2=length(cislo2)+1;
return (l1>l2?l1:l2);
}
int main( int argc, char * argv[] ){
unsigned int cislo1;
unsigned int cislo2;
int w=15; //sirka vystupniho streamu
cout << "Zadej 1.cislo" << endl;
cin >> cislo1;
cout << "Zadej 2.cislo" << endl;
cin >> cislo2;
unsigned int soucin=cislo1*cislo2;
}
cout << "\n" << setw(w) << setfill(' ') << cislo1 << endl;
cout << setw(w-length(cislo2)) << setfill(' ') << "." << cislo2 << endl;
int ml=maxlength(cislo1,cislo2);
cout << setw(w-ml) << setfill(' ') << "" << setw(ml) << setfill('-') << "" << endl;
int d=0;
do{
cout << setw(w-d) << setfill(' ') << (cislo2%10)*cislo1 << endl;
d++;
} while((cislo2/=10)!=0);
int ls=length(soucin);
cout << setw(w-ls) << setfill(' ') << "" << setw(ls) << setfill('-')<< "" <<endl;
cout << setw(w) << setfill(' ') << soucin << endl;
return 0;
}
Fórum › C / C++
Znaménka

myslis jako ze nedokazete najit jak se dela podminka cislo je mensi nez 0?
if ( cislo < 0 ) {
// a pak vynasobit cislo -1 ?
cislo = -1*cislo; // nebo trochu uspornejsi ale naprosto stejny cislo *= -1;
}
To volnaduse : proste nez s tema cislama neco zacnete delat musite je prevest na kladny.. v tomdle nic slozityho neni.. musi se proste myslet postupne..
pocitac dela jen to co je naprogramovane... nevidi co bude .. a co bylo muze videt jen, kdyz mu to ukazete v promenne, jinak to zapomene

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 65 hostů
Podobná vlákna
Doplňte znaménka — založil Bald3rr
IF znamenka s písmeny — založil David
Definování znaménka mínis — založil Matěj Míček
číslo se a bez znaménka - jak určit — založil Ato
Moderátoři diskuze