how can i do ?

W

wahid

• Write a program that will take an integer
number n input from the user, and then
output the value of the sum of the series
• S = 12 + 22 + 32+….. + n2
 
I

Ian Collins

wahid said:
• Write a program that will take an integer
number n input from the user, and then
output the value of the sum of the series
• S = 12 + 22 + 32+….. + n2

Solve the problem on paper, then convert it to code, then post your
attempt if you have problems.

Asking people to do your homework is a great way to learn absolutely
nothing and fail your exams.
 
W

wahid

• Write a program that will take an integer
number n input from the user, and then
output the value of the sum of the series
• S = 1^2 + 2^2 + 3^2+….. + n^2
 
S

Seebs

? Write a program that will take an integer
number n input from the user, and then
output the value of the sum of the series
? S = 12 + 22 + 32+?.. + n2

You never post thank-you notes to the people who do your homework, why is
that?

-s
 
K

Keith Thompson

wahid said:
• Write a program that will take an integer
number n input from the user, and then
output the value of the sum of the series
• S = 12 + 22 + 32+….. + n2

Go away and do your own damned homework.
 
N

Nick

Seebs said:
You never post thank-you notes to the people who do your homework, why is
that?

He did to the last one (the print the three digits). There were some
beautiful answers there, I wonder which one he used.
 
I

Ike Naar

#include<stdio.h>/**/
int main(void){int n;
scanf("%d",&n);printf
("%d\n",(((n<<1)+(1<<
1)+1)*n+1)*n/(((1<<1)
+1)<<1));return 1-1;}
 
A

Antoninus Twink

• Write a program that will take an integer
number n input from the user, and then
output the value of the sum of the series
• S = 12 + 22 + 32+….. + n2

#include <stdio.h>
#include <limits.h>

int main(void)
{
int d, rv = 0;
fputs("Enter a Number: ", stdout);
fflush(stdout);
if(scanf("%d", &d) == 1 && d > 0) {
if((7. + 5 * d) * d > ULLONG_MAX) {
fputs("Integer overflow\n", stderr);
rv = 1;
} else
printf("12 + 22 + ... + %d2 = %llu\n", d, (7ULL + 5 * d) * d);
}
else {
fputs("Invalid input: needed a positive integer\n", stderr);
rv = 1;
}
return rv;
}
 
E

Eric Sosman

• Write a program that will take an integer
number n input from the user, and then
output the value of the sum of the series
• S = 12 + 22 + 32+….. + n2

Sounds like a bad idea. If the program takes an integer
from the user each time it is run, how can the user get the
integer back again? Think of how inconvenient it would be if
you gave away 3, say, and could never use it again: You could
never again sing "Three Blind Mice" or listen to the Threepenny
Opera or celebrate Epiphany, or ride in a train powered by an
electrified third rail. The Holy Trinity would reject you, and
the entire month of March would be lost to you forever!

You could, I guess, select an "unlikely" integer as the
one to give away, but it seems awfully hard to choose one that
you're certain you'll never need again. The very fact that
you chose it once indicates that it is far more likely to crop
up than almost all other integers. Also, if you give the
integer to an early version of the program, discover that the
program has a bug, and fix it, how will you test the fix? You
no longer have the integer that caused the misbehavior, and
can thus not be sure you've actually fixed the problem.

Wahid, I think you should go to your teacher and point out
these serious drawbacks. Tell him or her that the assignment
threatens those who complete it with a sort of progressive
innumeracy by depriving them of another integer each time they
run the code. Tell him or her, in short, that he or she is
either a sadist or a fool, and ask for a substitute assignment.
No, not "ask," but "demand:" it's your right as a diligent
student.
 
K

Kenny McCormack

Go away and do your own damned homework.

Temper, temper, my good man!

Where the Kiki we all know and love, who is so eager to "help" people?

That is your reason for being here, isn't it?
(As you've said in the past, when I've asked you directly why you are here)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top