Thursday, 6 April 2017

Geeksforgeeks Solution For " Find the number of sub-arrays having even sum "

GeeksforGeeks Solution For Hard Domain .Below You Can Find The Solution Of  School Basic ,Easy ,Medium . Or Hackerrank Solution You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- Find the number of sub-arrays having even sum

Submit Your Solution :- Click Here 

Solution :- 

#include <iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int i,j,n,cnt=0;
        cin>>n;
        int ar[n];
        for(i=0;i<n;i++)
        cin>>ar[i];
        
        for(i=0;i<n;i++)
        {
            int sum=0;
            for(j=i;j<n;j++)
            {
                sum+=ar[j];
                if(sum%2==0)
                cnt++;
            }
        }
        cout<<cnt<<endl;

    }
    return 0;
}

Output:-



Geeksforgeeks Solution For " Find the number of sub-arrays having even sum "

No comments:
Write comments

Recommended Posts × +