Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

,sxrjd / 1 / prog1

.cpp
Скачиваний:
26
Добавлен:
27.03.2016
Размер:
1.78 Кб
Скачать
#include <stdio.h>     // include standard input-output functions
#include <iostream.h>  // include stream input-output functions

// global variables declaration type: float (double)
double f1, f2, f3;

/*
   function fib() calculates Fibonacci on
   global variables f1, f2, f3
*/
double fib(){
    f3 = f1 + f2;
    f1 = f2;
    f2 = f3;
    return f3;
}

// execution starts with the function main()
int main(){
    int integer1, integer2;  // local to main() variables declaration type: integer

    cout << "Enter first integer: ";
    cin >> integer1;
    cout << "Enter second integer: ";
    cin >> integer2;

// add, store result in new declared variable res
    int res = integer1 + integer2;
    cout << "The sum is: " << res << "\n";

// integer ratio !!!
    res = integer1/integer2;
    cout << "The int ratio is: " << res << "\n";

// maximum using if else
    if( integer1 > integer2) res = integer1;
    else res = integer2;
    cout << "The max is: " << res << "\n";

// maximum using if without else
    res = integer1;
    if( integer2 > integer1) res = integer2;
    cout << "The max is: " << res << "\n";

    f1 = 10.3;
    f2 = 3.6;
// float to integer
    integer1 = f1;
    integer2 = f2;
    cout << "float to integer: " << integer1 << "\t" << integer2 << "\n";
    
// integer to float
    f1 = integer1;
    f2 = integer2;
    cout << "integer to float: " << f1 << "\t" << f2 << "\n";

    
// float ratio
    cout << "The float ratio is: " << f1/f2 << "\n";
    
// Fibonacci    
    cout << "Fibonacci: " << fib() << "\n";
    cout << "Fibonacci: " << fib() << "\n";
    cout << "Fibonacci: " << fib() << "\n";
// wait Enter to close window
    getchar();

    return 0;
}

Соседние файлы в папке 1
  • #
    27.03.2016105 б23p1.mk
  • #
    27.03.2016641 б24p1.mk1
  • #
    27.03.201629.52 Кб25p1.sym
  • #
    27.03.2016413 б23p1.tgt
  • #
    27.03.2016228 б23p1.wpj
  • #
    27.03.20161.78 Кб26prog1.cpp
  • #
    27.03.20165.06 Кб25prog1.obj