Wednesday, December 2, 2015

Uri problem 1060 solve

Problem :

Positive Numbers

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Write a program that reads 6 numbers. These numbers will only be positive or negative (disregard null values). Print the total number of positive numbers.

Input

Six numbers, positive and/or negative.

Output

Print a message with the total number of positive numbers.
Sample InputSample Output
7
-5
6
-3.4
4.6
12
4 valores positivos

Solution:

#include<stdio.h>
 
int main()
{
    int i , sum, inp[6];
    for(i = 0; i < 6; i++)
        scanf("%d",&inp[i]);
        sum = 0;
        for(i = 0; i < 6; i++){
            if(inp[i] >= 0)
                sum = sum + 1;
            else
                sum = sum;
        }
        printf("%d valores positivos\n",sum);
 
    return 0;
}

No comments:

Post a Comment