Write a C++ program to display Pascal's triangle.
Test data:
Input the number of rows : 5
Expected output:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Write a program in C++ to find the number ang sum in all integer between 100 and 200 which are divisible by 9.
Expected output:
Number between 100 and 200, divisible by 9.
108 117 126 135 144 153 162 171 180 189 198
#include<iostream>
using namespace std;
int main(){
int r,col=1,b,x,n;
cout << "\n\n Outputing Pascal's triangle:\n";
cout << " Enter number of rows: ";
cin >> r;
for(x=0;x<r;x++)
{
for(b=1;b<=r-x;b++)
cout<<" ";
for(n=0;n<=x;n++)
{
if (n==0||x==0)
col=1;
else
col=col*(x-n+1)/n;
cout<<col<<" ";
}
cout<<endl;
}
}
Comments
Leave a comment