Search This Blog

Monday 1 April 2019

Skill Rack Daily Challenge Solution - 02/04/2019

 Skill Rack

Daily Challenge Solution

Date : 02/04/2019



ProgramID- 8456
Comma Separated Positive Integers

The program must accept N integers separated by a comma as the input. The program must print the positive integers separated by a comma among the N integers as the output. If there is no positive integer then the program must print -1 as the output.

Boundary Condition(s):
1 <= N <= 100
-999 <= Each integer value <= 999

Input Format:
The first line contains the value of N.
The second line contains N integers separated by a comma.

Output Format:
The first line contains either the positive integers separated by a comma or -1.

Example Input/Output 1:
Input:
5
12,-10,78,-5,-99
Output:
12,78
Explanation:
The positive integers are 12 and 78. So they are separated by a comma and printed as the output.
Example Input/Output 2:
 
Input:
6
-41,-93,-91,-54,-59,-88
Output:
-1


Solution :
------------------------------------------------------------------
#include<stdio.h>
#include <stdlib.h>

int main()
{
    int n,c=0,a[100],b[100],i,j=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d,",&a[i]);
        if(a[i]>0)
        {
            b[j]=a[i];
            j++;
        }
        else
        {
            c++;
        }
    }
    if(c!=n)
    for(i=0;i<j;i++)
    {
        printf("%d",b[i]);
        if(i<j-1)
        {
            printf(",");
        }
    }
    else
    {
        printf("-1");
    }
 
    return 0;

}

 ------------------------------------------------------------------

No comments:

Post a Comment