C Program Sum Series N Natural Numbers

C Program Sum Series N Natural Numbers /* C program to calculate and print sum of the series 1+2+3+4+…+n C program to print the sum of all natural numbers from 1 to n. */ #include<stdio.h> int main() { int i,n,sum; printf(“Enter the value of n: “); scanf(“%d”,&n); sum=0; /* loop to calculate sum from 1… Read More »

Loading

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