Posts

Showing posts with the label while-loop

Program to add only positive numbers.

  ap2l #include <iostream> using namespace std ; //Program to add only positive numbers.(while loop) int main (){     int number ;     int sum = 0 ;     cout << "Enter a number:" ;     cin >> number ;     while ( number >= 0 ){         sum = sum + number ;         cout << "Enter a number:" ;         cin >> number ;             }       cout << "Sum of all the positive numbers are " << sum << endl ;         return 0 ; }

Program to test loop-while

  ap2k #include <iostream> using namespace std ;  //program to test loop-while.   int main (){     int n ;     cin >> n ;     while ( n > 0 ){         cout << n << endl ;         cin >> n ;     }       return 0 ;  }