Round function question.

Asked 2 years ago, Updated 2 years ago, 104 views

Write a program that takes n natural numbers and outputs a relative size based on the smallest value.

ex) 2 3 4 5 5-> 1 2 2 3 3

It has to come out as . What's wrong?

#include <stdio.h>
#define size 5

int main() 
{
    int i, min;
    int arr[size] = { 0, };
    int trans;
    double N;

    printf ("Enter 5 natural numbers:");

    for (i = 0; i < size; i++)
    {
        scanf("%d", &arr[i]); 
    }

    min = arr[0];

    for (i = 0; i < size; i++)
    {
        if (arr[i] < min)
        {
            min = arr[i]; 
        }
    }
    printf ("Minimum value is %d".\n", min);

    for (i = 0; i < size; i++)
    {
        N = arr[i] / min;
    }

    trans = (double)(N);

    for (i = 0; i < size; i++)
    {
        printf("%d", trans);
    }

}

rounding c

2022-09-20 17:27

1 Answers


    for (i = 0; i < size; i++)
    {
        N = (double) arr[i] / min;

        trans = N + 0.5;

        printf("%d ", trans);
    }


2022-09-20 17:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.