Category Archives: Basic C Programs for Beginners

C Program Sum of One to N by Recursion

C Program Sum of One to N by Recursion /*C Program To Add all natural numbers 1 to N Using Recursion */ #include <stdio.h> /* Function prototype */ int sumNumbers(int n); /* main function */ int main() { int num; printf(“Enter a positive integer\nto add all numbers upto: “); scanf(“%d”, &num); printf(“Sum of Numbers Upto… Read More »

Loading

C Program Reverse Number by Recursion

C Program Reverse Number by Recursion /* C Program Reverse Number By Recursion*/ #include <stdio.h> /* function prototype */ long reverse(long); /* main function */ int main() { long num, rev; printf(“Enter a number to be reversed by Recursion: “); scanf(“%ld”, &num); rev = reverse(num); printf(“Reverse Number = %ld\n”, rev); return 0; } long reverse(long… Read More »

Loading

C Program Fibonacci Series by Recursion

C Program Fibonacci Series by Recursion Output How many terms of Fibonacci series are required? 7 Using Recursion, the Fibonacci series terms are: 0, 1, 1, 2, 3, 5, 8, ——————————– Process exited after 25.97 seconds with return value 0 Press any key to continue . . . #include<stdio.h> /* function prototype*/ int fibo(int); int… Read More »

Loading

C Program Power By Recursion

C Program Power By Recursion Output Please Enter base: 2 Please Enter exponent: 4 2^4 = 16 ——————————– Process exited after 32.63 seconds with return value 0 Press any key to continue . . . /*************************************************** * C Program to Find N Power P using recursion * Sample Run of Recursive power function * Enter… Read More »

Loading

C Program Find Factorial by Recursion

C Program Find Factorial by Recursion #include<stdio.h> // prototype for user defined recursive function long factorial(int); // main function int main() { int n; long fact; printf("Enter a number to find its factorial using Recursion="); scanf("%d", &n); if (n < 0) printf("Factorial of negative integers isn't defined.\n"); else { fact = factorial(n); printf("%d! = %ld",… Read More »

Loading

C Program Merge Sort

C Program Merge Sort /* C Program Merge Sort uses merge sort method to sort N element array in ascending order */ #include<stdio.h> void mergesort(int a[],int i,int j); void merge(int a[],int i1,int j1,int i2,int j2); int main() { int a[100],n,i; printf(“Enter no of elements in the Array [Maximum 100]: “); scanf(“%d”,&n); /*Input array elements (numbers… Read More »

Loading