answersLogoWhite

0

#include

using std::cout;
using std::endl;

int main()
{
int number(1);
cout << endl << "Enter a number to calculate sum of given number of elements: ";
cin >> number;

//using loop for
int sum(0);
for(int i(1); i <= number; i++)
{
sum += i;
}
cout << endl << "Sum of " << number << " loop for gives: " << sum << endl;

//using loop while
sum = 0;
int index(1);
while (index <= number)
{
sum += index;
++index;
}
cout << endl << "Sum of " << number << " loop while gives: " << sum << endl;

//using loop do while
sum = 0;
int index(1);
do
{
sum += index;
++index;
}while (index <= number);
cout << endl << "Sum of " << number << " loop do while gives: " << sum << endl;

system("PAUSE");
return 0;
}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

How infinite loop is created using while in C programming?

while (2*2==4) printf ("Still running\n");


What are the example of programming?

Virtually any software used by a computer is an example of programming. While the user will interact with an interface most of the time, the developer will create the entire thing using many, many lines of code.


Why c is call structured programming?

Because you can use programming structures, namely: sequence, selection (if, switch) and repetition (while, for, do-while)


What programming language is used for www.threadless.com?

HTML and javascript. While viewing www.threadless.com or any site for that matter. If you are using Internet Explorer, Click View-&gt;Source.


What is multiprogaming?

Its a form of programming while multitasking


How do you mask an object in programming?

Masking an object in programming typically involves creating a representation that selectively displays or processes certain aspects of that object while hiding others. This can be achieved using techniques such as encapsulation in object-oriented programming, where private properties are not accessible outside the object, or by applying filters in data processing to exclude unwanted information. Additionally, in graphics programming, masking can involve using a mask image or shape to define which parts of an object are visible or affected by operations.


What is the difference between online and offline programming?

Online programming is programming that has to occur while the computer or other device is connected to the internet. Offline programming doe not require an internet connection.


When a DVR is paused how does it catch up to real time in the programming?

It's recording the programming while it is paused.


Structured programming concepts in c?

Structured programming is a programming paradigm aimed on improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures and for and while loops - in contrast to using simple tests and jumps such as the goto statement which could lead to "spaghetti code" which is both difficult to follow and to maintain.


What is the difference between static and dynamic programming?

in static programming properties, methods and object have to be declared first, while in dynamic programming they can be created at runtime. This is usually due to the fact that the dynamic programming language is an interpreted language.


Why are matrices used for representation while programming?

Let me correct you: two-dimensional arrays are used in programming to represent matrices. (Matrices are objects of mathematics, arrays are objects of programming.)


How can you define null statement in loop in C programming?

If you are using for loop for(;;); or you can also define condition and iterations but the loop has to close there itself without any statement inside it. In the similar way you can define while and do while loop without any statement.