// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;
int fib(int n){
int arr[n]={0,1};
// arr[n]={0,1};
for(int i= 0 ;i<=n;i++){
// 0 1 1 2 3 5 8 13
arr[i+2]=arr[i]+arr[i+1];
cout << arr[i] << " ";
}
cout<< endl;
cout << arr[n];
return 0;
}
int main() {
fib(6);
return 0;
}//Enter you code here.
//Please indent properly.
<?php
//program to find the common elements of the two array
//here we have to array A and B from which w have to find the common element
//first we sort then using merge sort and after then for traversing through
//the array in one iteration we can find the comman elements the given array
//this is an inspace algorithm meansno extra space is needed
//best case time complexity=O(nlogn)
//O(nlogn)-> for sorting
//O(n)-> for while loop to find comman element
//average case time complexity=O(nlogn)
//O(nlogn)-> for sorting
//O(n)-> for while loop to find comman element
//worst case time complexity =O(nlogn)
//O(nlogn)-> for sorting
//O(n)-> for while loop to find comman element
$A=array(3,4,5,6,7,8,9,10,36,58,27,48); $B=array(3,10,4,5,6,8,12,24,37,27,50); $counter1=0;
$counter2=0;
while(($counter1< $size1) && ($counter2)<($size2))//traversing through the array
{
if ($A[$counter1] == $B[$counter2])
{
array_push($commonArray,$A[$counter1]); //to enter comman element in the output array $counter1=$counter1+1;
$counter2=$counter2+1;
}
else if ($A[$counter1] < $B[$counter2])
{
$counter1=$counter1+1; }
else
{
$counter2=$counter2+1;
}
}
print_r($commonArray);//to print the output array ?>
Ly8gT25saW5lIEMrKyBjb21waWxlciB0byBydW4gQysrIHByb2dyYW0gb25saW5lCiNpbmNsdWRlIDxpb3N0cmVhbT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IGZpYihpbnQgbil7CiAgICBpbnQgYXJyW25dPXswLDF9OwogICAgLy8gYXJyW25dPXswLDF9OwogICAgZm9yKGludCBpPSAwIDtpPD1uO2krKyl7CiAgICAgICAgLy8gMCAxIDEgMiAzIDUgOCAxMwogICAgICAgIGFycltpKzJdPWFycltpXSthcnJbaSsxXTsKICAgICAgICAgICBjb3V0IDw8IGFycltpXSA8PCAiICAiO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