write a function – oriented program that calculates the sum
of the squares from 1 to n. thus, if the input is 3, the
output is 14

Answer Posted / sreejesh1987


void main()
{
int sum(int d);int n;
clrscr();
printf("Enter the no: ");
scanf("%d",&n);
printf("\nSum of squares upto %d is %d",n,sum(n));
getch();

}
int sum(int x)
{
int sum=0;
while(x>0)
{
sum+=x*x;
x--;
}
return sum;
}

Is This Answer Correct ?    5 Yes 10 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

write a program to calculate the amount of investment after a period n years if the principal investors was p and interest is calculated using compound interest,formular=a=p(1+r)^n

2366


Create a program to read two random data set in two files named data1.txt and data2.txt manifold contains integer numbers, whereas data2.txt file contains the float type numbers. Simpanlahmasing each into 2 pieces of data that is an array of type integer array and an array of type float, then calculate the average numbers in the second array.

2152


1+1/2!+1/3!+...+1/n!

1945


Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.

4578


write a program to convert temperature from fa height into celcius and vise versa,use modular programming

2441






How to swap two ASCII numbers?

2449


write a program that reads a series of strings and prints only those strings begging with letter "b"

2674


Ask the user to input three positive integers M, N and q. Make the 2 dimensional array of integers with size MxN, where all the elements of I (I = 1,…,M) line will be members of geometrical progression with first element equal to the number of line (I) and denominator q.

3395


find level of following tree (state, parent) " J,D I,D H,C E,B F,B G,C B,A D,A C,A A,& K,E L,E L,F M,F N,G O,H P,I P,H Q,I R,J S,K U,P T,L

2010


develop a program to calculate and print body mass index for 200 employees

2216


A suduco given & u hv 2 check if it is incomplete(blanks left),or correct or incorrect

2407


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.

2065


Teta-Omeg-Big-Oh Show that f(n) = n2 + 3n3 is ;(n3).

3193


What output does the following code generate? Why? What output does it generate if you make A::Foo() a pure virtual function? class A { A() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; class B : public A { B() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; int main(int, char**) { A objectA; B objectB; return 0; }

644


What output does this program generate as shown? Why? class A { A() { cout << "A::A()" << endl; } ~A() { cout << "A::~A()" << endl; throw "A::exception"; } }; class B { B() { cout << "B::B()" << endl; throw "B::exception"; } ~B() { cout << "B::~B()"; } }; int main(int, char**) { try { cout << "Entering try...catch block" << endl; A objectA; B objectB; cout << "Exiting try...catch block" << endl; } catch (char* ex) { cout << ex << endl; } return 0; }

579