answersLogoWhite

0

There are better ways to do this, but the following example will get the job done all the same.

#include <iostream>

int foo(int & X, int & Y)

{

if( X > Y ) // Ensure X < Y.

{

int T = X; X = Y; Y = T; // Swap.

}

int Total = X;

if( X!=Y) // Skip summation when equal (1 to 1 = 1).

{

int Addend = X; // Begin summation.

while(++Addend <= Y) Total += Addend;

}

return( Total );

}

int main()

{

int X, Y;

std::cout << "Enter start value: ";

std::cin >> X;

std::cout << "Enter end value: ";

std::cin >> Y;

std::cout << std::endl;

std::cout << "The summation of " << X << " to " << Y << " is: " << foo( X,Y);

std::cout << std::endl;

return( 0 );

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

Write a program that read phrase and print the number of lower-case letter in it using function of counting?

write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program


Write a c program for matrix addition using function?

#include&lt;


Write a Program to convert decimal number into hexadecimal no without using function and string?

This is not a question.


Write a program to calculate the area of a cylinder using a function?

give an example of calculation of mathematics


Can you write a program without using any semicolon inside the main function?

not possible dude


How do you write a c program to find area of rectangle using function?

There will be a function in it like this: double RectangleArea (double a, double b) { return a*b; }


How do you write a program using function that counts the number of vowels in a string in java language?

Use text-editor notepad++


Write a program to swap two numbers using function?

swap (int *a, int *b) { *a ^= *b; *b ^= *a; *a ^= *b; }


How do you write a programm in c plus plus without using function main?

I don't think its possible. Every C++ program must at least have the main function.


How do you write a program using the gotoxy statement and print function to display letters of the alphabet on the computer screen?

There is no gotoxy statement in C.


Write a sample program using ASPNET explaining all the syntax and semantics of the program?

write a sample program using asp.net explaining all the syntax and semantics of the program


Write a program to calculate the average of n numbers using array?

C:#includeint main(){int num,sum,avg=0,i;printf("enter a number");scanf("%d",&num);for(i=0;i