answersLogoWhite

0

Factorial of a number using do while loop in C?

Updated: 8/18/2019
User Avatar

Wiki User

13y ago

Best Answer

this is the java code to enjoy

convert it to C or take the idea and go on.

why ?! because the syntax is the same !!

file name : Class1.java

------------------------

package mypackage1;

public class Class1

{

public long fact(int a)

{

int answer = a;

do

{

if (a==0)

{

return a;

}

answer = a*(--a);

} while(a<=0);

return answer;

}

public static void main(String [] arg)

{

Class1 c1 = new Class1();

System.out.println(c1.fact(4));

}

-------------------

note: the code will work will all java versions

enjoy the coding

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Factorial of a number using do while loop in C?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program using while loop?

//program to find the factorial value f any number using while loop #include&lt;stdio.h&gt; void main() { int i,n,fact=1; printf("Enter the number\n"); scanf("%d",&amp;n); i=n; while (i&gt;=1) { fact=fact*i; i--; } printf("The factorial value=%d",fact); } the above is a program for calculating tha factorial value of any number which is entered by the user


Find factorial at given number using do while loop?

Actually, a for loop is more appropriate in this case. With while, it would be something like the following pseudocode - adapt to your favorite programming language:function factorial(n)result = 1factor = 1while factor


Write a recursive procedure to compute the factorial of a number?

#include &lt;iostream&gt; using namespace std; int main() { int i, number=0, factorial=1; // User input must be an integer number between 1 and 10 while(number&lt;1 number&gt;10) { cout &lt;&lt; "Enter integer number (1-10) = "; cin &gt;&gt; number; } // Calculate the factorial with a FOR loop for(i=1; i&lt;=number; i++) { factorial = factorial*i; } // Output result cout &lt;&lt; "Factorial = " &lt;&lt; factorial &lt;&lt; endl;


7 Write a C program to compute the factorial of a number using for loop?

int factorial(int n) { int i; int f=1; for(i=2;i&lt;=n;++i) f*=i; return f; }


Using while loop Write a program find the factors of a number?

by this program you can find the factorial: #include&lt;iostream&gt; using namespace std; main() { int n,x,f=1; cin&gt;&gt; n; x=0; while(x&lt;n) { x++; f= f*x; } cout&lt;&lt;"factorial is"&lt;&lt;f&lt;&lt;"\n"; system("pause"); return 0; }


How do you write a program to compute and print the factorial of given number using a while loop in c plus plus?

// returns n! int fact(final int n) { // keep track of factorial calculation in f // f starts at n, and we will multiply it by all integers less than n int f = n; // loop from n-1 down to 2 for(int i = (n - 1); i &gt; 1; --i) { // increase our total product f *= i; } return f; }


What is a C programming to calculate the sum of 1-2-3-4-5 and so on using while loop a for loop and a do while loop?

#include using std::cout;using std::endl;int main(){int number(1);cout number;//using loop forint sum(0);for(int i(1); i


What is a factorial loop?

An example in Java, to compute 10!: int factorial = 1; for(int i = 1; i &lt; 11; i++) { factorial *= i; }


Factorial in c program using for loop?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int i,n,fact=1; clrscr(); printf("enter the number"); scanf("%d",&amp;n); for(i=1;i&lt;=n;i++) printf("%d",n); fact=fact*i; { printf("the factorial is=%d",fact); } getch(); } By:-Abhishek Goyal(goyal.abhi40@yahoo.com)


Write a C-like program fragment that calculate the factorial function for argment 12 with do while loop?

#!/usr/bin/perl print factorial($ARGV[11]); sub factorial { my($num) = @_; if($num == 1) { return 1; # stop at 1, factorial doesn't multiply times zero } else { return $num * factorial($num - 1); # call factorial function recursively } }


Sample code ofn factorial using for loop in C langguage?

#include #include void main(){int n,i;long int fact=1;clrscr();printf("Enter number = ");scanf("%d",&n);for(i=1;i


What is a loop type?

A Loop is a programming language construct that instructs the processor to repeat a sequence of operations a number of times until a specific condition is reached. There are different types of loops. They are: * for loop * while loop * do while loop