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

Write code for the multiplication of COMPLEX numbers?

0 Answers   IBM,


readers and writers problem

1 Answers   Cognizant,


Write a function- oriented to convert the input dollar(s) into its equivalent peso. Assume that one dollar is equivalent to 51.60

1 Answers  


How to swap two ASCII numbers?

0 Answers  


A string of charaters were given. Find the highest occurance of a character and display that character. eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE OUTPUT: E

1 Answers  


Given 1 to n random number, find top 10 maximum numbers and explain the time complexity of the algorithm.

1 Answers   IMO, NetApp,


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  


Assume in University Every student in university as entity, prepare a class for student that store the roll no, name, dob of student, and make funtion of deletion, manipulation, addition of student record.

0 Answers  


Code for Small C++ Class to Transform Any Static Control into a Hyperlink Control?

0 Answers   Wipro,


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

0 Answers  


how to write a program that opens a file and display in reverse order?

0 Answers   SMC,


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

3 Answers  


Categories