Advertisement
Guest User

Untitled

a guest
Mar 12th, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <windows.h>   // WinApi header
  4.  
  5. using namespace std;
  6.  
  7. void gotoxy(int x, int y)
  8. {
  9.   COORD c;
  10.   c.X = x - 1;
  11.   c.Y = y - 1;
  12.   SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
  13. }
  14.  
  15. long int potega(long int podstawa, int wykladnik)
  16. {
  17.     int wynik = 1;
  18.     for (int i = 0; i<wykladnik; i++)
  19.         wynik*=podstawa;
  20.  
  21.     return wynik;
  22. }
  23.  
  24. int main(int argc, char** argv) {      
  25.        
  26.         int n;
  27.         double a;
  28.         double suma=0;
  29.        
  30.         //teraz ten balagan od zmiany kolorow:
  31.         HANDLE  hConsole;
  32.         int k=0;
  33.          hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  34.          
  35.         for(n=1; ;n++){
  36.             //a=(double)(potega(-1, n-1))/((2*n)-1);
  37.        
  38.                 a = (double)(n % 2 == 1 ? 1.0 : -1.0) / ((2 * n) - 1);
  39.                 SetConsoleTextAttribute(hConsole, k);
  40.                 cout<<k<<a<<" \t";
  41.                 suma+=a;
  42.                 cout<<k<<suma<<endl;
  43.                 if(k<255){
  44.                 k++;
  45.                  }
  46.                 else k=0;
  47.                    
  48.                 if(kbhit() && getch()) break;
  49.            
  50.  
  51.                
  52.         }
  53.        
  54.  
  55.  
  56.         return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement