Dremendo Tag Line

Input 10 numbers and find the sum of 2 digit positive numbers using for loop in C++

for Loop - Question 6

In this question, we will see how to input 10 numbers and find the sum of 2 digit, positive numbers only in C++ programming using for loop. To know more about for loop click on the for loop lesson.

Q6) Write a program in C++ to input 10 numbers and find the sum of 2 digit, positive numbers only using for loop.

Program

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int i,n,s=0;

    cout<<"Enter 10 numbers\n";
    for(i=1; i<=10; i=i+1)
    {
        cin>>n;
        if(n>=10 && n<=99)
        {
            s=s+n;
        }
    }
    cout<<"Sum of 2 digit positive numbers = "<<s;
    return 0;
}

Output

Enter 10 numbers
2
4
18
20
1
9
3
5
32
46
Sum of 2 digit positive numbers = 116
video-poster