M
MARQUITOS51
This program is intended to read values of an array until the sum of
those values reaches 100. Then at the element where the sum becomes
greater thatn 100 store a -1.0 to denote the end of the array. I want
to know why the program is printing the numbers twice on the screen.
#include<stdio.h>
int main()
{
float n[100]={10,20,30,40,50,60,70,80,90,100}, sum=0.0;
int i;
for(i=0; sum<=100.0; i++)
{
sum=sum+n;
if (sum<=100.0)
{printf("%.1f \n", n);}
else
n=-1;
{printf("%.1f \n", n);}
}
return 0;
}
those values reaches 100. Then at the element where the sum becomes
greater thatn 100 store a -1.0 to denote the end of the array. I want
to know why the program is printing the numbers twice on the screen.
#include<stdio.h>
int main()
{
float n[100]={10,20,30,40,50,60,70,80,90,100}, sum=0.0;
int i;
for(i=0; sum<=100.0; i++)
{
sum=sum+n;
if (sum<=100.0)
{printf("%.1f \n", n);}
else
n=-1;
{printf("%.1f \n", n);}
}
return 0;
}