I use a while
to loop
n
to divide numbers Print the quotient want to say for example if the user entered n = 3, then the program will ask for 3 numbers. Say the user entered 2, 2, and 3. The program does the following: 2/2/3 and then prints the answer (i.e. 0.3333). I have a program which, apart from that, uses a while
loop for division and multiplication, but in division, it divides all the numbers entered in 1/2/2/3 . How do I fix it? Here's the code:
contains # lt; Stdio.h & gt; #to & lt include, stdlib.h & gt; #to & lt include, conio.h & gt; Zero main (zero) {int n, k = 0; Float total = 1, number; Printf ("Enter the number of elements \ n you want to divide:"); Scanf ("% d", & amp; n); Printf ("Please enter% d number one at a time: \ n", n); While (a & lt; n) {scanf ("% f", and number); Total = number / number; K = k + 1; } Printf ("% d number of numbers =% f \ n", n, total); _getch (); }
change
total = number / number ;
to
if (k == 0) total = number; Other total = total / number;
Comments
Post a Comment