c++ programs for practice

Here you can find sample and simple c++ programs that are helpful for computer science students

Pages

  • Home
  • About Me
  • Share Your Programs

Wednesday, November 20, 2013

Program to print the first 10 lines of Pascal's Triangle


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
long triangle(int x,int y);
int main()
{
clrscr();
const lines=10;
for (int i=0;i<lines;i++)
for (int j=1;j<lines-i;j++)
cout << setw(2) << " ";
for (int j=0;j<=i;j++)
cout << setw(4) << triangle(i,j);
cout << endl;
getch();
}
long triangle(int x,int y)
{
if(x<0||y<0||y>x)
return 0;
long c=1;
for (int i=1;i<=y;i++,x--)
c=c*x/i;
return c;
}

To know about Pascal's Triangle Click Here
Posted by Athul KV at 5:44 PM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Labels: for loop, function, mathematical calculations
Newer Posts Older Posts Home
Subscribe to: Posts (Atom)

Popular Posts

  • Program for multiplication of matrix using " class "
  • Program to enter your height in centimeters and convert into feet and inches
  • Program for Newton's Law of Gravitation
  • Program To Find Out The Final Velocity Of A Body Using Linear Motion Equation
  • Program to display all prime numbers less than 100
  • Program to accept 20 numbers and display it in ascending order and descending order - Bubble sort
  • Program to find out Economic Order Quantity (EOQ)
  • Program to find the sum of all the elements of a matrix
  • Program to find out the volume of cone
  • Program to print the sum of first n natural numbers using " while loop "

About Me

My photo
Athul KV
View my complete profile

Labels

  • array (4)
  • bubble sort (1)
  • class (1)
  • conditional operator (1)
  • do-while loop (1)
  • for loop (21)
  • function (3)
  • if-else (10)
  • linear search (1)
  • loop (10)
  • mathematical calculations (19)
  • matrix (4)
  • nested loop (8)
  • new and delete operators (1)
  • pointer (1)
  • string (3)
  • switch (1)
  • two dimensional array (5)
  • while loop (4)

Facebook Fans

Blog Archive

  • ►  2014 (1)
    • ►  December (1)
  • ▼  2013 (44)
    • ▼  November (1)
      • Program to print the first 10 lines of Pascal's Tr...
    • ►  October (2)
    • ►  August (6)
    • ►  July (35)

Contact Form

Name

Email *

Message *

Total Pageviews

c++ programs for practice Donot Copy. Powered by Blogger.