Back

#include<stdio.h>
#include<stdlib.h>

#define SIZE 10
int getline(char s[], int lim);

int main()
{
  char line[SIZE];
  float sum=0.0;
  while ((getline(line,SIZE))>0)
   sum+=atof(line);
  printf("Sum = %6.3f \n",sum);
  return 0;
}

int getline(char s[], int lim)
{
  int c, i;
  i=0;
  while(--lim > 0 && (c=getchar()) != EOF && c!='\n')
    s[i++]=c;
  if(c=='\n')
   s[i++]=c;
  s[i]='\0';
 return i;
}

Top