Showing category "for loop" (Show all posts)

fibonacci series-for loop

Posted by sameer on Monday, June 8, 2009, In : for loop 
//Fibonacci series
//program to implement fibonacci series of a number
#include<iostream.h
void main()
{
int n,first=0,second=1,third;
cout<<"enter the number of elements=";
cinn;
cout<<"\n"<<first<<"  ";
cout<<second<<"  ";
for(int i=0;i<n;i++)
{
third=first+second;
cout<<third<<"  ";
first=second;
second=third;
}
}

fibonacci series is a series in which every third number is the sum of the two preceding numbers.In this program e use three numbers first,second,third.first we print the values of the first an...

Continue reading ...
 

Factorial-for loop

Posted by sameer on Monday, June 8, 2009, In : for loop 
//FACTORIAL
//program to implement factorial of a number
#include<iostream.h
void main()
{
int number,fact=1;
cout<<"enter the number=";
cinnumber;
for(int i=1;i<=number;i++)
fact=fact*i;
cout<<"\nfactorial="<<fact;
}

The logic of the program is that we are first giving a value 1 to the factorial and then repeatedly multiplying all the numbers from 1 to the input number, to the factorial of the number by using a for loop.this is done by incrementing the value of i from 1 to the input number and then puti...
Continue reading ...
 
 

About Me


I AM KUNAL KUMAR SINGH AND IHAVE GREAT PROGRAMMING KNOWLEDGE WHICH I HAVE USED TO DESIGN THIS SITE . KINDY TAKE AS MUCH HELP AND INFO FROM MY SITE AS POSSIBLE .

 

DONATE  ANY AMOUNT FOR C++NOW 

Recent Posts