Tuesday, April 7, 2015

Sum of the Digit in c program

#include
void main () 
{
  int num, count = 1;
  float sum = 0.0;

  cout << endl;
  while (count <= 3) 
{
    cout << "Enter a number: ";
    cin >> num;
    sum = sum + num;
    count = count + 1;
  }
  cout << "Average is " << sum / count << endl;
}

There are several ways of fixing the problem. Here is one of them:
*/

void main () 
{
  int num, count = 1;
  float sum = 0.0;

  cout << endl;
  while (count <= 3)
 {
    cout << "Enter a number: ";
    cin >> num;
    sum = sum + num;
    count = count + 1;
  }
  cout << "Average is " << sum / (count - 1) << endl;
}


#include
int inc (int);
void main () 
{
  int i = 3;
  int j;

  j = inc (i);
  cout << j << endl;
}

int inc (int a) 
{
  return(a+1);
}


No comments:

Post a Comment