Advertisement
Shailrshah

Sum of and number of odd numbers

Apr 18th, 2013
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int count=0, sum=0,n;
  5.     while(1)
  6.     {
  7.         printf("Enter integer: \n");
  8.         scanf("%d",&n);
  9.         if(n<0)
  10.             break;
  11.         if(n%2)
  12.         {
  13.             ++count;
  14.             sum+=n;
  15.         }
  16.     }
  17.     printf("The sum is %d and the number of odd numbers is %d",sum,count);
  18.     return 0;
  19. }
  20. //Output
  21. //Enter integer:
  22. //3
  23. //Enter integer:
  24. //2
  25. //Enter integer:
  26. //5
  27. //Enter integer:
  28. //2
  29. //Enter integer:
  30. //-123
  31. //The sum is 8 and the number of odd numbers is 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement