Write a program to calculate the following
i want a c++program for this condition
1+4+9+16+….+100

Like this (1^2+2^2)

Hint use function pow(a,b)

Answers were Sorted based on User's Feedback



Write a program to calculate the following i want a c++program for this condition 1+4+9+16+….+1..

Answer / yogeshwaran

#include<iostream>
using namespace std;
#include<math.h>
main()
{
double j=0,l=0;
double k=0;
int max=0;

cout<<"enter a maximum value"<<endl;
cin>>max;
for(int i=1;l<=max;i++)
{
j=pow(i,2);
l=j;
j=j+k;
k=j;
}
cout<<"value is "<<j<<endl;
}

Is This Answer Correct ?    42 Yes 5 No

Write a program to calculate the following i want a c++program for this condition 1+4+9+16+….+1..

Answer / chaithanya kumar

#include<iostream>
#include<math.h>
using namespace std;
main()
{
double j=0,l=0;
double k=0;
int max,i;

cout<<"enter a maximum value"<<endl;
cin>>max;
for(i=1;i<=max;i++)
{
j=pow(i,2);
j=j+k;
k=j;
}
cout<<"value is j= "<<j<<endl;
}

Is This Answer Correct ?    1 Yes 0 No

Write a program to calculate the following i want a c++program for this condition 1+4+9+16+….+1..

Answer / ashok ak

#include<iostream>
using namespace std;
int main()
{
int a=0,n;
cout<<"Enter the Number ";
cin>>n;
for(int i=1;i<=n;i++)
a+=pow(i,2);
cout<<"The Sum of Total is "<<a;
return 0;
}

Is This Answer Correct ?    0 Yes 1 No

Write a program to calculate the following i want a c++program for this condition 1+4+9+16+….+1..

Answer / b sohan lal

#include<iostream.h>
void main()
{
init i,n,k,sum;
clrscr();
sum=0;
cout<<"enter the max limit:";
cin>>n;
i=1;
while(k<=n)
{
k=i*2;
sum=sum+k;
i++;
}
cout<<"result="<<sum;
getch();
}

Is This Answer Correct ?    6 Yes 10 No

Post New Answer

More C++ General Interview Questions

What is c++ w3school?

0 Answers  


Which is not a valid keyword a) public b) protected c) guarded

0 Answers  


What is the type of 'this' pointer?

0 Answers  


What you mean by early binding and late binding? How it is related to dynamic binding?

1 Answers  


What will i and j equal after the code below is executed? Explain your answer.

1 Answers  






What is the main use of c++?

0 Answers  


Why the usage of pointers in C++ is not recommended ?

0 Answers   TCS,


Define friend function.

0 Answers  


what are the decision making statements in C++? Explain if statement with an example?

0 Answers  


Which of the Standard C++ casts can be used to perform a ?safe? downcast: a) reinterpret_cast b) dynamic_cast c) static_cast d) const_cast

2 Answers   Quark,


explain the reference variable in c++?

0 Answers  


What are the main characteristics of C++ as a programming language?

1 Answers  


Categories