answersLogoWhite

0


Best Answer

//to calculate using while

#include<stdio.h>

#include<conio.h>

void main()

{ int count

float average,sum;

sum=0;

count=0;

while(count<N)

scanf("%f",n)

sum=sum+count

count=count+1

}

average=sum/n

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

7y ago

#include<iostream>

#include<sstream>

#include<vector>

#include<numeric> // for std::accumulate()

// If the given string represents a natural number then return its value.

// Otherwise return 0 to indicate error (note: 0 is not a natural number).

unsigned string_to_natural (const std::string& str) {

if (str.empty() str.find_first_not_of("0123456789")!=str.npos) return 0;

std::stringstream ss;

ss<<str;

unsigned u;

if (ss>>u)

return u;

return 0;

}

int main (void) {

std::vector<unsigned> ages;

while (true) {

std::cout<<"Input age (100 to end): ";

std::string input;

std::cin.clear();

std::cin>>input;

unsigned age {string_to_natural (input)};

if (age==100) break;

if (age==0) {

std::cerr<<"Invalid input.\n";

continue;

}

ages.push_back (age);

}

std::cout<<"Average age: "<<std::accumulate (ages.begin(), ages.end(), 0)/ages.size()<<std::endl;

}

This answer is:
User Avatar

User Avatar

Anonymous

Lvl 1
4y ago

#include

#include

void main()

{

int a,b,c,d,e,total,name,rollno,i;

float avg;

clrscr();

i=1;

while(i

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program to calculate average using while loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Is it possible to make a program using for and not with while?

The following cases are all possible:- program without any for and while- program without for- program without while- program with both for and while


How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


Where the data and program kept while the processor is using them?

In the RAM


C program algorithm for simple interest using while loop?

Not used


What is the role of internal reporting system while using the loyalty program?

eleporo


Write a program that will graph using for loop?

A = 5do{statement;A = A + 1;} while (A < 10)


How do you write a c program to print n no's required using while loop?

int i=0; while (i++&lt;n) { /*...*/ }


Using while loop write a program which calculates the product of digits from 1 to 5 and also show these nos vertically?

Using while loop, write a program which calculates the product of digits from 1 to 5 and also show these no's vertically.


Where can you find your word processor?

The Google word processor is one component of the Google Documents program. This program can be found on the Google website. The program gets average reviews and is recommended for people who only use word processing once in a while.


Skype headsets can be used for what purpose?

Skype headsets are hands-free devices that allow you to hear and talk into a microphone while using the Skype program. They are used to make the Skype users experience easier while doing other things and using the Skype program.


What calculation should be used to calculate the correct average atomic mass of chlorine?

While jerking it, take 2 and divide it by the mass.


How do you write a program that calculate factorial in javascript?

function factorial(n) { var x=1; while(n&gt;1) x*=(n--); return x; }