A
A
annozzer2015-10-13 20:53:47
C++ / C#
annozzer, 2015-10-13 20:53:47

How to enter fractional numbers in an array?

I think many people know the task of rounding the number E to 1<=n<=25
So, I want to do it using >> and << but I don’t know how to show in the array that the number is fractional,
i.e. I want to write what is at index 0 the number is 2, and the index has 1 dot, etc.,
or is there another way to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nadz Goldman, 2015-10-13
@nadz

Too simple a question that quickly googles.
Taken, again, from Google.
But in fact it is so.
What's the difference - a fractional number or not? It's in the array. We refer to the index and that's it.

#include <iostream>
#define N 5
 
using namespace std;
 
int main()
{
    float arr[N];
    int count = 0;
    for(int i = 0; i < N; i++)
    {
        cout << "Введите " << i+1 << " элемент: ";
        cin >> arr[i];
        if(arr[i])
            count++;
    }
    cout << "Кол-во ненулевых: " << count << endl;
    return 0;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question