In this tutorial, you would learn the beginning of programming using C++. We do talk here for various cycles including the Fibonacci series made through the do-while cycle.
// Lesson1.cpp : Sets the entry point of console application. // #include "stdafx.h" #include #include #include #include #include using namespace std; class Fibonacci { public: int a, b, c; void generate(int); }; void Fibonacci::generate(int n) { a = 0; b = 1; cout << a << " " << b; for (int i = 1; i <= n - 2; i++) { c = a + b; cout << " " << c; a = b; b = c; } } int _tmain(int argc, _TCHAR* argv[]) { float x; // float y; // declaration of variables float n; // int b; int i = 0; b = 1; //we set the value of b = 1 cout << "Addition of two numbers, to cancel it please click -1 " << endl; while (b != -1) //creates a ring so the program would run //as much as you want to add numbers { // the following code gives to the end user to add // two numbers by calling and represents the result cout << "Input number x = "; cin >> x; cout << "Input number y = "; cin >> y; n = (x + y); cout << "Result of n = " << n << endl; //The following code sets the value of b n // from command line to set up if the ring is closed through //the value while input is -1 cout << "Continuing, [-1] to be stopped"; cin >> b; //sets the input value at b cout << "The value of b =" << b << endl; if (b == 2) cout << "The given value is equal to 2"<< endl; } cout << endl; system("pause"); cout << endl; cout << "Listing of the numbers from 1 till 10" << endl; for (i = 0; i < 10; i++) { cout << "Number " << i << " value " << i << endl; } cout << endl; system("pause"); cout << endl; cout << "Skipping of one cycle" << endl; for (i = 0; i < 10; i++) { if (i == 5) { cout << endl; continue; }; cout << "The value of " << i << endl; } cout << endl; system("pause"); cout << endl; cout << "Stopping of the ring upon a given number" << endl; for (i = 0; i < 10; i++) { if (i == 5) break; cout << "Value of " << i << endl; } cout << endl; system("pause"); cout << endl; cout << "Inverse listing" << endl; for (i = 10; i >= 0; i--) { cout << "Value of " << i << endl; } cout << endl; system("pause"); cout << endl; cout << "Splitting of numbers in even and odd numbers" << endl; cout << endl; int sumOdd = 0, sumEven = 0, countOdd= 0, countEven= 0; // Declaration and initialization of integer numbers for (i = 0; i < 10; i++) { if (i % 2 == 0) { countEven++; // increment by one sumEven += i;// adding } else { countOdd++; // increment by one sumOdd += i; // adding } } cout << endl; system("pause"); cout << endl; printf_s("Sums: %d even, %d oddnNumber %d even, %d odd", sumEven, sumOdd, countEven, countOdd); cout << endl; system("pause"); cout << endl; cout << "Fibonacci sequence" << endl; cout << "Input the number of terms that you need into the sequence: "; int n1; cin >> n1; Fibonacci fibonacci; fibonacci.generate(n1); cout << endl; system("pause"); return 0; }
Click here to download the code:
The code project in C++ of VS C++ 2014 also GNU CC