C++ Program To Generate Fibonacci Series: Factorial
C++ Program To Generate Fibonacci Series: Factorial
series
#include<iostream>
main()
{
int n, c, first = 0, second = 1, next;
cout << "Enter the number of terms of Fibonacci series you want" << endl;
cin >> n;
cout << "First " << n << " terms of Fibonacci series are :- " << endl;
return 0;
}
Factorial
#include<iostream>
int main()
{
int num,factorial=1;
cin>>num;
for(int a=1;a<=num;a++)
factorial=factorial*a;
return 0;
int main()
{
int n;
cout << "Factorial of " << n << " = " << factorial(n);
return 0;
}
int factorial(int n)
{
if(n > 1)
return n * factorial(n - 1);
else
return 1;
}
Following C++ program ask to the user to enter a string to reverse it and display the
reversed string on the screen:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char str[100], temp;
int i=0, j;
cout<<"Enter the String : ";
gets(str);
i=0;
j=strlen(str)-1;
while(i<j)
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
i++;
j--;
}
cout<<"Reverse of the String = "<<str;
getch();
}
In this program we enter an elements in any two array and then these two array (elements of array)
Example
#include<iostream.h>
#include<conio.h>
void main()
{
int a[10],b[10],c[20],i;
clrscr();
cout<<"Enter Elements in 1st Array: ";
for(i=0;i<10;i++)
{
cin>>a[i];
}
cout<<"Enter Elements in 2nd Array: ";
for(i=0;i<10;i++)
{
cin>>b[i];
}
cout<<"\nElements of Array After Merge: ";
for(i=0;i<10;i++)
{
c[i]=a[i];
c[i+10]=b[i];
}
for(i=0;i<20;i++)
{
cout<<c[i];
}
getch();
}
x = x + y; // x now becomes 15
y = x - y; // y becomes 10
x = x - y; // x becomes 5