Advertisement
Pierog195

obliczanie x^n na 3 sposoby

Nov 27th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <windows.h>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. for (;;)
  11. {
  12. char wybor; int a,b,licz=0,wynik=1;
  13. cout <<"Program do podnoszenia licz do potegi na 3 sposoby"<<endl;
  14. cout <<"-------------------------------------------------"<<endl;
  15. cout <<"Podaj liczbe ktora ma byc opdniesiona do potegi: ";
  16. cin >>a;
  17. cout <<"I do jakiej potegi podnniesc: ";
  18. cin >> b;
  19. system("cls");
  20. cout <<"-------------------------------------------------"<<endl;
  21. cout <<" MENU"<<endl;
  22. cout <<"-------------------------------------------------"<<endl;
  23. cout <<"1. do...while"<<endl;
  24. cout <<"2. while"<<endl;
  25. cout <<"3. for"<<endl;
  26. cout <<"4. wyjdz z programu"<<endl;
  27. cout <<"Wybieram: ";
  28. wybor=getch();
  29. system("cls");
  30.  
  31.  
  32. switch(wybor)
  33. {
  34. case '1':
  35. {
  36. do
  37. {
  38. wynik=wynik*a;
  39. licz++;
  40. }
  41. while (licz<b);
  42. cout <<"wymnik to: "<< wynik;
  43. getch();
  44. system("cls");
  45. break;
  46. }
  47. case '2':
  48. {
  49. while (licz<b)
  50. {
  51. wynik=wynik*a;
  52. licz++;
  53. }
  54. cout <<"Wynik to: "<<wynik;
  55. getch();
  56. system("cls");
  57. break;
  58. }
  59. case '3':
  60. {
  61. for (;licz<b;licz++)
  62. {
  63. wynik=wynik*a;
  64. }
  65. cout <<"Wynik to: "<< wynik;
  66. getch();
  67. system("cls");
  68. break;
  69. }
  70. case '4':
  71. {
  72. return 0;
  73. break;
  74. }
  75. default:
  76. {
  77. cout <<"Nie ma takiej opcji w menu";
  78. getch();
  79. system("cls");
  80. break;
  81. }
  82. }
  83.  
  84.  
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement