can someone help me find something that i can depend on making sourcecodes using while, do while, for while...thx

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by vaibhav1983

A simple counting program.

For example, to get the factorial of n where n is in int. The result is the final value of fac.

``````long fac=1;
int i=1;
while ( i<=n ) { // the condition for execution of the loop
fac *= i;  //  the previous factorial (factorial of i-1)is multiplied by the current i
i++;  // i has one increment
}``````
``````long fac=1;
int i=1;
do{
fac *= i; //  the previous factorial (factorial of i-1)is multiplied by the current i

i++; // i has one increment
}while ( i<=n ) // the condition for execution of the loop``````
``````long fac=1;
for (int i=1; i<=n; i++) // the control variable i is initiated with 1
fac = fac*i; //  the previous factorial (factorial of i-1)is multiplied by the current i``````

Edited by tong1: n/a

I guess these are the basics of any language. Y do u have to ask people to write code for u here?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.