Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

PROGRAM TO READ NUMBER FROM KEYBOARD TILL USER PRESS 999 AND SUM OF ONLY POSITIVE NUMBER

Program to read numbers from keyboard continuously till the user presses 999 and to find the sum of only positive numbers

#include<stdio.h>

void main()

{

          int num,sum=0;

          printf("Enter numbers to :\n");

          while(1)

          {

                   scanf("%d",&num);

                   if(num==999)

                   break;

                   else

                   {

                       if(num>0)

                       sum+=num;

                   }

          }

          printf("Sum of positive numbers is %d",sum);

}


Post a Comment

0 Comments