Guest User

Untitled

a guest
Jan 31st, 2021
852
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main(){
  7.  
  8. int N=0, K=3;
  9. cout <<"Enter the size you want your pascal triangle: ";
  10. cin >> N;
  11.  
  12. vector<int> x;
  13. vector<int> p;
  14. x.assign(2,1);
  15. for(int i=1; i<N+1;i++){
  16. cout<< " ";
  17. }
  18. cout << "1" <<endl;
  19. for(int i=1; i<N;i++){
  20. cout<< " ";
  21. }
  22. cout << "1 1"<<endl;
  23. int j = 1;
  24. while(K<N+1){
  25. p.assign(K,1);
  26. for(int i=1; i<N-j;i++){
  27. cout<< " ";
  28. }
  29. cout<< "1 ";
  30. for(int i=1; i<K-1;i++){
  31. p[0]=1;
  32. p[K-1]=1;
  33. p[i]=x[i-1]+x[i];
  34. if(p[i]>6){
  35. cout << p[i]%7 ;
  36. cout << " ";
  37. }
  38. else{
  39. cout << p[i];
  40. cout << " ";
  41. }
  42. }
  43. cout << "1 ";
  44. x.assign(K,1);
  45. for(int j=1; j<K-1; j++){
  46. x[j]=p[j];
  47. }
  48. K++;
  49. j++;
  50. cout << ""<<endl;
  51.  
  52. }
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment