Sunday, September 10, 2017

Two Digits Numbers Sum

Accept an array of N values and print the sum S of all the two-digit numbers present in the array. If there are no two-digit numbers, print 0.

Input Format:
First line contains the size N Second line contains N values seperated by a space

Output Format:
The first line contains S.

Boundary Condition: 1 < N < 1000

Example Input/Output 1:
Input:
5
23 898 6 54 21
Ouput:
98

Example Input/Output 2:
Input:
6
231 898 6 541 2 900
Ouput:
0

Solution:
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
 int a,n,s=0;
 cin>>n;
 for(int i=0;i<n;i++)
 {
     cin>>a;
     if(a<100&&a>9)
      s+=a;
 }
 cout<<s;
}
Share: