0

Hi
I'm biggener in c language and I hope from every one in this forum help me.
now I will start first Q

How I can write a c program to comput the sum of sequres of numbers from m to n .
for exsample : from3 ot 6 : 3^2+4^2+5^2+6^2=

4
Contributors
5
Replies
6
Views
11 Years
Discussion Span
Last Post by cime63
0

Hi
I'm biggener in c language and I hope from every one in this forum help me.
now I will start first Q

How I can write a c program to comput the sum of sequres of numbers from m to n .
for exsample:(from3 ot 6) : 3^2+4^2+5^2+6^2=

think about it like this !

ask the user to enter two numbers the first(m) and the last (n)
second ya gonna count from m to n so from 3 to 6 ! (for loop)
with condition that 3 is included and 6 is included.
zn multiply each number by it self and add it to the total (you create a total to carry all the sum)
after that output the total.

0

I wrote this program put I don not know whare is th mestake

#incluode<stdio.h>
main()
{
int m,n,sum=0,i=m;
printf("enter two numbers one greater than other");
scanf("%d%d",&m,&n);
for(i=m;i<=n;i++)
{
sum=sum+(i*i);
printf(" sum sequare from %d to sequare%d is %d",m,n,sum);
}
}

0

> printf(" sum sequare from %d to sequare%d is %d",m,n,sum);
Maybe put this line outside the for loop?

Does it print the right answer on the last iteration of the loop?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.