Program to generate Fibonacci Series
#include <stdio.h>
void main()
{
int OldNum, NewNum, FibNum, MaxNum;
printf("
Generate Fibonacci Numbers till what number? ");
scanf("%d", &MaxNum);
OldNum=0;
NewNum=1;
FibNum = OldNum + NewNum;
printf("%d, %d, %d, ", OldNum, NewNum, FibNum);
for(;;)
{
OldNum = NewNum;
NewNum = FibNum;
FibNum = OldNum + NewNum;
if(FibNum > MaxNum)
{
printf("
");
exit(1);
}
printf("%d, ", FibNum);
}
}
#include <iostream>
using namespace std;
void main()
{
unsigned int oldValue, newValue, fibNum, maxNum;
// initialize value...
oldValue = 0;
newValue = fibNum = 1;
cout << "Generate Fibonacci Numbers till what number?" << endl;
cin >> maxNum;
// display initial values...
cout << oldValue << ", " << newValue << ", " << fibNum;
// Now to calculate up to maxNum...
while (newValue + fibNum < maxNum)
{
oldValue = newValue;
newValue = fibNum;
fibNum = oldValue + newValue;
// change to output comma before fibNum vice always having it at the end
cout << ", " << fibNum;
}
}
#include <iostream>
using namespace std;
int main() {
unsigned int factorial = 1;
unsigned int number;
cout << "Calculate the factorial of a number." << endl;
cout << "Enter a positive integer." << endl;
cin >> number;
for(int i=1; i <= number; i++) {
factorial *= i;
}
cout << "The factorial of " << number << " is " << factorial << "." << endl;
return 0;
}
As for the rest of you, shame on you for giving the answers away. Shame, I say.