C Program to Calculate Factorial of a number using Recursion
Write a program to calculate the factorial of a number. Use the concept of recursion
instead of using loops.
instead of using loops.
#include<stdio.h>
main()
{
int a, fact;
printf("\nEnter any number: ");
scanf ("%d", &a);
fact=rec (a);
printf("\nFactorial Value = %d", fact);
}
rec (int x)
{
int f;
if (x==1)
return (1);
else
f=x*rec(x-1);
return (f);
}
Comments
w
wo
wor
worl
world
using single dimension array.. pls help me...
{
int i=0,j;
char *p;
printf ("Enter String: ");
scanf ("%s", p);
for(i = 1; i <= strlen(p); i++)
{
for (j = 0; j < i; j++)
{
printf ("%c", *(p + j));
}
printf ("\n");
}
getch();
}
I am learning C from book by Yashwant Kanetkar Let Us C. In that I am in chapter 9th Puppeting on screen where i was doing function strcat which was explained in book and in end its said by author that I leave it up to you for writing a function xstrcat to concenate two string. I am trying to solve it but i am not able to can you please help me with that?
I m doing my first year BE .
This program helps me to write a record.
Very very thank you sir/madam....
I m doing my first year BE .
This program helps me to write a record.
Very very thank you sir/madam....
1!=1
2!=2
3!=6
...........
........
........ up to
10!=362880
and also need to know about a coding for same kind of out put ,but user enter the integer.
please i need ur help
>loop statements like for, while, do while.
>conditional operators like if, case.
>just you can use the below
arithmetic operators like + , - , * , % , /, ++, --.??!!
send me immediatly on my orkut profile kumail_shaikh@yahoo.com.
it can be viewed at
http://bbb-letuscsolutions.blogspot.com/
http://www.a2zhacks.blogspot.com to learn C,C++,VB programming.
email me:karthik_reddy42@sify.com
Cegonsoft
#include
int main()
{
int num = 0, val = 0, fact = 0;
printf("Enter a non-negative number \n");
scanf("%d", &num);
fact = num;
val = num;
if (num == 0 || num == 1)
{
printf("%d! is 1 \n", num);
}
else
{
while (num > 2)
{
fact = fact * --num;
}
printf("%d! is %d \n", val, fact);
}
return 0;
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Factoriel
{
class Program
{
static void Main(string[] args)
{
myLabel:
int val1, val2;
double factoriel = 1;
Console.Write("Enter an integer: ");
val1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
val2 = val1;
if (val1 < 0)
{
Console.WriteLine("The entered value is not valid! \nPlease enter a value greater than zero.");
Console.WriteLine();
goto myLabel;
}
if (val1 == 0 || val1 == 1)
{
Console.WriteLine("{0}! = 1", val1);
Console.WriteLine();
goto myLabel;
}
if (val1 > 1)
{
while (val2 > 1)
{
factoriel = factoriel * val2;
val2 = val2 - 1;
}
Console.WriteLine("{0}!= {1} ", val1, factoriel);
Console.WriteLine();
goto myLabel;
}
}
}
}
#include
void main(){
int a,b,c,ch=0;
printf("CALCULATOR\n");
printf("PRESS 1 for ADDITION\n");
printf("PRESS 2 for SUBTRACTION\n");
printf("PRESS 3 for MULTIPLICATION\n");
printf("PRESS 4 for DIVSION\n");
printf("PRESS 5 for MODULO\n");
printf("PRESS 6 for LEAP YEAR FINDER\n");
printf("PRESS 7 for REVERSE A NUMBER\n");
printf("PRESS 8 for GRADE FINDER\n");
printf("PRESS 9 for INR to USD\n");
printf("PRESS 10 for INR to EUR\n");
printf("PRESS 11 for INR to GBP\n");
printf("PRESS 12 for INR to AUD\n");
printf("PRESS 13 for INR to Dirham\n");
printf("PRESS 14 for INR to Yuan\n");
printf("PRESS 15 for INR to Canadian Dollar\n");
scanf("%d",&ch);
//choice
switch(ch){
case 1:
printf("ADDITION\nPlease enter the first value");
scanf("%d", &a);
printf("Please enter the second value");
scanf("%d",&b);
c=a+b;
printf("The answer is %d",c);
break;
case 2:
printf("SUBTRACTION\nPlease enter the first value");
scanf("%d", &a);
printf("Please enter the second value");
scanf("%d",&b);
c=a-b;
printf("The answer is %d",c);
break;
case 3:
printf("MULTIPLICATION\nPlease enter the first value");
scanf("%d", &a);
printf("Please enter the second value");
scanf("%d",&b);
c=a*b;
printf("The answer is %d",c);
break;
case 5:
printf("MODULO\nPlease enter the first value");
scanf("%d", &a);
printf("Please enter the second value");
scanf("%d",&b);
c=a%b;
printf("The answer is %d",c);
case 6:
printf("LEAP YEAR FINDER\nPlease Enter the YEAR\n");
scanf("%d",&a);
if(a%4==0){printf("It is a LEAP YEAR");}
else{printf("It is not a LEAP YEAR");}
break;
case 7:
printf("REVERSE A NUMBER\nPlease Enter a 3 integer number\n");
scanf("%d",&a);
b=a%10;
c=a/10%10;
d=a/100%10;
printf("%d%d%d",b,c,d);
break;
case 8:
printf("STUDENT GRADE FINDER\nPlease Enter the Marks\n");
scanf("%d",&a);
if(a>=0 && a<=50){printf("FAIL");}
else if(a>=51 && a<=60){printf("C GRADE");}
else if(a>=61 && a<=70){printf("B GRADE");}
else if(a>=71 && a<=100){printf("A GRADE");}
else if(a>=101 || a<=-1){printf("INVALID NUMBER");}
break;
case 9:
printf("INR to USD\nWrite the amount of money");
scanf("%d", &a);
9
}
}
*****
****
***
**
*
*****
&****
&&***
&&&**
&&&&*
#include
main()
{
int i,j,k,l;
int matrix[3][3],matri[3][3],matr[3][3];
printf("Enter 1st matrix: \n");
for (i=0;i<3;++i)
{
printf("\nEnter #%d row: ",(i+1));
for (j=0;j<3;++j)
scanf("%d",&matrix[i][j]);
}
printf("\n\n");
printf("Enter 2nd matrix: \n");
for (i=0;i<3;++i)
{
printf("\nEnter #%d row: ",(i+1));
for (j=0;j<3;++j)
scanf("%d",&matri[i][j]);
}
/*printf("\n\n");
/for (i=0;i<3;++i)
/{
/for (j=0;j<3;++j)
}*/
matr[i][j]={{0,0,0},{0,0,0},{0,0,0}}
for (j=0;j<3;++j)
{
for (i=0;i<3;++i)
{
for (l=0;l<3;++l)
matr[i][j] = matr[i][j] + (matrix[i][l])*(matri[l][j]);
}
}
printf("The resultant matrix is:\n\n");
for (i=0;i<3;++i)
{
for (j=0;j<3;++j)
printf("%4d",matr[i][j]);
printf("\n\n");
}
}
#include
#include
void main ()
{
int i , n , fac=1;
printf ("Enter n to get the factorial");
scanf("%d",&n);
for (i=1;i<=n;i++)
{
fac=fac*i ;
}
printf (" Factorial=%d",fac);
getch();
}
Nıs ther postıve number between 1 and 20.then write c# programm to calculate factorial of as follow
1!=1
2!=2
n!=........
you have to visit this place :O
www.gamerdudezgd.com
PS : thanks for the tutorial
www.extremeprogrammings.blogspot.in
Kata-Kata Mutiara Terbaru
Hasil Liga Champions
Download Smadav Terbaru
Download Lagu dan Lirik Black Glasses Atiqah Hasiholan Feat Eru
Download Windows 8 dengan Serial Number
Kata Kata Romantis Terbaru 2012
Download Wallpaper Animasi Bergerak
Biodata Iqbaal Dhiafakhri Ramadhan
Biodata AKB48
Cara Memakai Jilbab Segi Empat
Kata Kata Renungan Terbaik
Kumpulan Daftar Situs Edit Foto Online
NISN Cara mencari Nomor Induk Siswa Nasional
Lowongan CPNS 2012 - 2013 Terbaru
any one solve this question and send my email id:-
123shanky321gupta@gmail.com
int main(){
int i,f=1,num;
printf("Enter a number: ");
scanf("%d",&num);
for(i=1;i<=num;i++)
f=f*i;
printf("Factorial of %d is: %d",num,f);
return 0;
}
#include
int main(){
long f=1;
int i,num,min,max;
printf("Enter the minimum range: ");
scanf("%d",&min);
printf("Enter the maximum range: ");
scanf("%d",&max);
printf("Factorial series in given range: ");
for(num=min;num<=max;num++){
f=1;
for(i=1;i<=num;i++)
f=f*i;
printf("%ld ",f);
}
return 0;
}
Sample output:
Enter the minimum range: 1
Enter the maximum range: 10
Factorial series in given range: 1 2 6 24 120 720 5040 40320 362880 3628800
contact on 09690376177
#include
#include
rec ( int a) ;
void main()
:
:
:
getch()
}
rec (int x)
{
:
:
:
}