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

Answers were Sorted based on User's Feedback



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

Answer / shams

#include<stdio.h>

int main()
{
int n,i,sum=0;
printf("Enter a number");
scanf("%d",&n);
for(i=1;i<=n;i++)
sum=sum+(i*i);
printf("Output:- %d",sum);
return 0;
}

Is This Answer Correct ?    19 Yes 12 No

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

Answer / hedto

int main()
{
int n,i,sum=0;
printf("Enter a number");
scanf("%d",&n);
for(i=1;i<=n;i++)
sum=sum+(i*i);
printf("Output:- %d",sum);
return 0;
}
int sum(int x)
{
int sum=0;
while(x>0)
{
sum+=x*x;
x--;
}
return sum;
}

Is This Answer Correct ?    5 Yes 2 No

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

Answer / 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

More C++ Code Interview Questions

Faster Computers Suppose you have a computer that requires 1 minute to solve problem instances of size 1000. What instance sizes can be run in 1 minute if you buy a new computer that runs 1000 times faster than the old one, assuming the following time complexities T(n) for our algorithm? (a) T(n) = O(n). (b) T(n) = O(n3). (c) T(n) = O(10n).

1 Answers   Qatar University,


what is virtual constroctor ? give an exam for it?-(parimal dhimmar)

2 Answers  


write a function that reverse the elements of an array in place.The function must accept only one pointer value and return void.

0 Answers   HCL, SRCASW,


write a c program, using for loop, that accepts and odds two numbers. The output must be the sum and the addens. This should be repeated 5 times while the first number is decremented by one and the second number is incremented by 1.

2 Answers   IBM, Infosys,


write a program that accepts a number and outputs its equivalent in words. take note that the maximum input is 3000

1 Answers   Alvin,






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

0 Answers   Jomo Kenyatta University,


Display Pattern: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 &#8230;

2 Answers   Mind Tree,


using repetition structure. Write a c program that will accept five numbers. The program should count and output the total count of even numbers and total count of add numbers.

2 Answers  


Code for Two Classes for Doing Gzip in Memory?

0 Answers  


void main() { int i,j=2; for(i=0;i<3;i++) if(j=i) cout<<"Lotus "; else cout<<"Rose "; } Its result is Rose Lotus Lotus.. How? Explain it?

2 Answers  


what is the difference between int &r and int& r

3 Answers  


Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

0 Answers   iGate,


Categories