Created
September 25, 2011 07:52
-
-
Save jithusunny/1240363 to your computer and use it in GitHub Desktop.
pascal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Filename: pascal.c | |
Blog: http://jithusunnyk.blogspot.com/ | |
Date: 24-09-11 | |
Description: Finds out the number at any given location(row, position) of Pascal's triangle. | |
Row-one is conventionally enumerated as 0 & position-one as 0, position-two as 1, etc*/ | |
#include <stdio.h> | |
int element_at(int row,int pos) { | |
if (pos == 0 || pos == row) | |
return 1; | |
return element_at(row - 1, pos - 1) + element_at(row - 1, pos); | |
} | |
int main() { | |
int row, pos; | |
printf("Enter row and position: "); | |
scanf("%d%d", &row, &pos); | |
if (pos > row) | |
printf("Invalid!\n"); | |
else | |
printf("Number: %d\n", element_at(row, pos)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment