Fibonacci series in C++
#include
#include
using namespace std;
int main()
{
int counter, n;
long last=1,next=0,sum;
cout<<"Enter the Number :";
cin>>n;
while(next
{
cout<
sum=next+last;
next=last;
last=sum;
}
getch();
return 0;
}
Output
Enter the Number :300
1
1
2
3
5
8
13
21
34
55
89
144
233
Hello World C++
#include
#include
using namespace std;
int main()
{
cout<<"My First C++ Program";
getch();
return 0;
}
Output
My First C++ Program
If Statement in C++
#include
#include
using namespace std;
int main()
{
int a;
cout<<"Enter the Number :";
cin>>a;
if(a > 10)
{
}
getch();
return 0;
}
Output
Enter the
Number :15
15 Is
Greater than 10
If..Else Statement in C++
#include
#include
using namespace std;
int main()
{
int a;
cout<<"Enter
the Number :";
cin>>a;
if(a > 10)
{
}
else
{
}
getch();
return 0;
}
Output
Enter
the Number :20
20
Is Greater than 10
For Loop Program in C++
#include
#include
using namespace std;
int main()
{
int a;
cout<<"Enter the Number :";
cin>>a;
for (int counter = 1; counter <= a; counter++)
{
cout<<"Execute "<
}
getch();
return 0;
}
Output
Enter the Number :5
Execute 1 time
Execute 2 time
Execute 3 time
Execute 4 time
Execute 5 time
While Loop Program in C++
#include
#include
using namespace std;
int main()
{
int a;
cout<<"Enter
the Number :";
cin>>a;
int counter = 1;
while (counter <= a)
{
cout<<"Execute While
"<
counter++;
}
getch();
return 0;
}
Output
Enter the Number :4
Execute While 1 time
Execute While 2 time
Execute While 3 time
Execute While 4 time
No comments:
Post a Comment