C program to print Pascal triangle 1 1 1 1 2 1 1 3 3 1 #include <stdio.h> long factorial ( int ) ; int main ( ) { int i , n , c ; printf ( "Enter the number of rows you wish to see in pascal triangle \n " ) ; scanf ( "%d" ,& n ) ; for ( i = 0 ; i < n ; i ++ ) { for ( c = 0 ; c <= ( n - i - 2 ) ; c ++ ) printf ( " " ) ; for ( c = 0 ; c <= i ; c ++ ) printf ( "%ld " , factorial ( i ) / ( factorial ( c ) * factorial ( i - c ) ) ) ; printf ( " \n " ) ; } return 0 ; } long factorial ( int n ) { int c ; long result = 1 ; for ( c = 1 ; c <= n ; c ++ ) result = result * c ; return result ; }
The JavaScript language Here we learn JavaScript, starting from scratch and go on to advanced concepts like OOP. We concentrate on the language itself here, with the minimum of environment-specific notes
C program to Calculate the Power of a Number Using Recursion /* Source Code to calculate power using recursive function */ #include <stdio.h> int power ( int n1 , int n2 ); int main () { int base , exp ; printf ( "Enter base number: " ); scanf ( "%d" ,& base ); printf ( "Enter power number(positive integer): " ); scanf ( "%d" ,& exp ); printf ( "%d^%d = %d" , base , exp , power ( base , exp )); return 0 ; } int power ( int base , int exp ) { if ( exp != 1 ) return ( base * power ( base , exp - 1 )); }
Comments
Post a Comment