[ create a new paste ] login | about

Link: http://codepad.org/rHNhgKqA    [ raw code | output | fork ]

C++, pasted on Jan 23:
#include <iostream>
#include <iomanip>
 
int search(const int [], int, int);
 
int main()
{
        int mass[10] = {1,2,3,4,5,6,7,8,9,10};
        int num;
 
        for(int i = 0; i < 10; i++)
                std::cout << std::setw(4) << mass[i];
 
        std::cout << "\nВведите число, которое нужно найти: ";
        std::cin >> num;
 
        int index = search(mass,9,num);
 
        if(index != -1)
                std::cout << "Число " << num << " найдено в позиции "
                          << index << std::endl;
        else
                std::cerr << "Число не найдено" << std::endl;
 
        return 0;
}
 
int search(const int mass[], int step, int num)
{
        if(mass[step] == num)
                return step;
        else if(!step)
                return -1;
 
        search(mass,step-1,num);
}


Output:
1
2
3
cc1plus: warnings being treated as errors
In function 'int search(const int*, int, int)':
Line 36: warning: control reaches end of non-void function


Create a new paste based on this one


Comments: