Answers for "function in c++ programming"

C++
21

how to declare a function in c++

// function example
#include <iostream>
using namespace std;

int addition (int a, int b)
{
  int r;
  r=a+b;
  return r;
}
Posted by: Guest on March-04-2020
0

functions questions c++

#include<iostream>
using namespace std;

int fib(int x)
{
    if(x == 0)
    {
        return 0;
    }
    else if(x==1)
    {
        return 1;
    }
    else
    {
        return fib(x-1)+fib(x-2);
    }
}

int main()
{
    cout << fib(0) << "n";
    cout << fib(1) << "n";
    cout << fib(2) << "n";
    cout << fib(3) << "n";
    cout << fib(4) << "n";
    cout << fib(5) << "n";
    return 0;
}
Posted by: Guest on January-17-2021

Browse Popular Code Answers by Language