DEV Community

Shreya
Shreya

Posted on

Daily Coding #1

Day - 1 (13th October 2020)
CodeSignal centuryFromYear.cpp

int centuryFromYear(int year) {

    if(year<=0)
       std::cout << "Enter valid year";

    else if (year <= 100)
        return 1;

    else if (year % 100 == 0)
        return year/ 100 ;
    else
        return year/ 100 + 1 ;
        return 0;
}

Enter fullscreen mode Exit fullscreen mode

GeeksForGeeks SumOfArrays.cpp

//User function template for C++
class Solution{
public:
    // function to return sum of elements
    // in an array of size n
    int sum(int arr[], int n) {
        // code here
        int SUM=0;
        for(int i=0; i<n; i++)
        {
            SUM+=arr[i];
        }
        return SUM;
    }

};
Enter fullscreen mode Exit fullscreen mode

Top comments (0)