File tree Expand file tree Collapse file tree 3 files changed +79
-0
lines changed Expand file tree Collapse file tree 3 files changed +79
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ collatz conjecture: a series for a number n in which if n even then the next number is n/2 ,but if n is odd then the next number is 3n+1.
3
+ this series continues till it reaches 1*/
4
+
5
+ #include <stdio.h>
6
+ int main ()
7
+ {
8
+ int n ,curr_no ;
9
+ scanf ("%d" ,& n ); //input number
10
+ curr_no = n ; //curr_no stores input number n
11
+ while (curr_no != 1 ) //loop till series reaches 1
12
+ {
13
+ if (curr_no %2 == 0 ) //condition for even number
14
+ {
15
+ curr_no = curr_no /2 ;
16
+ printf ("%d->" ,curr_no );
17
+ }
18
+ else
19
+ {
20
+ curr_no = (curr_no * 3 )+ 1 ; //condition for odd number
21
+ printf ("%d->" ,curr_no );
22
+ }
23
+ }
24
+ printf ("1" );
25
+ return 0 ;
26
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ code for computing nth catalan number
3
+ */
4
+ #include <stdio.h>
5
+ long int factorial (int x ) //long int for more than 10 factorial
6
+ {
7
+ int i ;
8
+ long int fac ; //fac stores x factorial
9
+ fac = x ;
10
+ for (i = 1 ;i < x ;i ++ ) //loop to calculate x factorial
11
+ {
12
+ fac = fac * (x - i );
13
+ }
14
+ return fac ; //returning x factorial
15
+ }
16
+ int main ()
17
+ {
18
+ long int f1 ,f2 ,f3 ; //long int for more than 10 factorial
19
+ int n ;
20
+ float C ; //C is catalan number for n;
21
+ scanf ("%d" ,& n );
22
+ f1 = factorial (2 * n );
23
+ f2 = factorial (n + 1 );
24
+ f3 = factorial (n );
25
+ C = f1 /(f2 * f3 ); //formula for catalan number for n
26
+ printf ("%0.2f" ,C );
27
+ return 0 ;
28
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ programme for computing number of zeroes at the end of factorial of a given number n
3
+ */
4
+ #include <stdio.h>
5
+ #include <math.h> //including math.h header file to use pow function
6
+ int main ()
7
+ {
8
+ int i ,n ,test = 0 ,count = 0 ;
9
+ //taking input number n
10
+ scanf ("%d" ,& n );
11
+
12
+ //looping from 1 till loop break
13
+ for (i = 1 ;;i ++ )
14
+ {
15
+ test = n /pow (5 ,i );//division of n by ith power of 5(storing in integer form)
16
+ if (test != 0 ) //condition for zeroes at end corresponding individual ith case
17
+ {
18
+ count = count + test ;
19
+ }
20
+ else
21
+ break ; //break the loop for if test=0
22
+ }
23
+ printf ("%d\n" ,count );
24
+ return 0 ;
25
+ }
You can’t perform that action at this time.
0 commit comments