answersLogoWhite

0


Best Answer

#include
#include
void main()
{
int sum_sqr(int n);
clrscr();
printf("%d",sum_sqr(5));//Sum of first 5 natural numbers' square values
getch();
}
int sum_sqr(int n)
{
int i,sum=0;
for(i=1;i<=n;i++)
{
sum=sum+(i*i);
}
return sum;
}

output:
55

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

9y ago

#include<iostream>

#include<random>

#include<time.h>

int main()

{

// pseudo-random number generator (range: 10 to 20, inclusive)

std::default_random_engine generator;

generator.seed ((unsigned) time (NULL));

std::uniform_int_distribution<unsigned> distribution (10, 20);

unsigned sum = 0;

unsigned n = distribution (generator);

for (unsigned i=0; i<n; ++i)

{

unsigned num = distribution (generator);

unsigned sqr = num * num;

std::cout << num << " squared is " << sqr << std::endl;

sum += sqr;

}

std::cout << "Sum of squares is " << sum << std::endl;

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

#include<stdio.h>

main()

{

int i,n,sum = 0;

printf("Program to find sum of n natural number\n");

printf("Enter the value of n ");

scanf("%d",&n);

for (i = 0;i <= n;i++)

{

sum = sum + i * i;

}

printf("The sum is %d",sum);

}

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

size_t sum_of_squares(size_t n)

{

size_t sum {0};

while (n)

{

sum += (n*n);

--n;

}

return sum;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to find the sum of squares of n natural numbers using c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a C Program to print sum of squares of odd numbers?

#include


Can you write every integer as the sum of two nonzero perfect squares?

No.First of all, you can't write negative numbers as sums of perfect squares at all - since all perfect squares are positive.Second, for natural numbers (1, 2, 3...) you may need up to 4 perfect squares: http://en.wikipedia.org/wiki/Lagrange's_four-square_theoremNo.First of all, you can't write negative numbers as sums of perfect squares at all - since all perfect squares are positive.Second, for natural numbers (1, 2, 3...) you may need up to 4 perfect squares: http://en.wikipedia.org/wiki/Lagrange's_four-square_theoremNo.First of all, you can't write negative numbers as sums of perfect squares at all - since all perfect squares are positive.Second, for natural numbers (1, 2, 3...) you may need up to 4 perfect squares: http://en.wikipedia.org/wiki/Lagrange's_four-square_theoremNo.First of all, you can't write negative numbers as sums of perfect squares at all - since all perfect squares are positive.Second, for natural numbers (1, 2, 3...) you may need up to 4 perfect squares: http://en.wikipedia.org/wiki/Lagrange's_four-square_theorem


Write a java script program to print first ten odd natural numbers in C?

Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.


Write a qbasic program to print the squares and cubes of first 10 natural numbers?

10 CLS 20 FOR n = 1 to 10 30 PRINT n, n^2, n^3 40 NEXT n 50 PRINT: PRINT: PRINT "Touch 'x' to go again, any other key to end." 60 INPUT a$ 70 IF a$ = "X" or a$ = "x" THEN 10 80 END


How. to. write an. algorthim. to find the. sum of. first. 15 natural. numbers?

Write an. Algorthim. To. Find the. Sum. Of. First15 natural. Numbers


Write a program in Lex to eliminate white space and collect numbers as a token?

write a lex program to delete space from the program


How do you write a program to find out the square and cube of first ten natural numbers in gw basic?

First you will need to have some basic programming knowledge. You can use this to help make the program that is needed.


How do you write an assembly language program to find the sum of n numbers using array?

write an assembly language program to find sum of N numbers


Write algorithm compute sum of square of N numbers?

1. Design an algorithm to compute sum of the squares of n numbers?


Shell program for gcd of three given numbers?

write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? check bellow link http://bashscript.blogspot.com/2009/08/gcd-of-more-than-two-numbers.html


How do you write a program in objective c numbers 1-100 prime numbers?

fdsgfhgdfhgdf


Could you Write a program for 8086 microprocessor that displays on the monitor the average of 2 numbers from an array?

How to write a program for mouse in microprocessor?