Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

what is the solution

0 views
Skip to first unread message

wahid

unread,
Jan 10, 2010, 2:08:12 AM1/10/10
to
• Write a program, that would take a number n
from user, and then output the square and
cube of first n natural numbers.

Sample Output
• Enter a number: 5
• Output for 1: square 1, cube 1
• Output for 2: square 4, cube 8
• Output for 3: square 9, cube 27
• Output for 4: square 16, cube 64
• Output for 5: square 25, cube 125

Ian Collins

unread,
Jan 10, 2010, 2:16:03 AM1/10/10
to
wahid wrote:
> � Write a program

There's a novel idea, why don't you give it a try?

--
Ian Collins

Francis Glassborow

unread,
Jan 10, 2010, 2:22:29 AM1/10/10
to
wahid wrote:
> � Write a program, that would take a number n

> from user, and then output the square and
> cube of first n natural numbers.
>
> Sample Output
> � Enter a number: 5
> � Output for 1: square 1, cube 1
> � Output for 2: square 4, cube 8
> � Output for 3: square 9, cube 27
> � Output for 4: square 16, cube 64
> � Output for 5: square 25, cube 125

This is the fourth problem you have posted here without any added
material from you.

Either you are an unbelievably lazy student, or you are too stupid to be
studying programming or you are an extremely bad troll.

If you genuinely want help, try producing your attempts at answering the
problems you are flooding us with. Post your code and we will do our
best to explain the errors.

Antoninus Twink

unread,
Jan 10, 2010, 8:16:44 AM1/10/10
to
On 10 Jan 2010 at 7:08, wahid wrote:
> • Write a program, that would take a number n from user, and then
> output the square and cube of first n natural numbers.

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

int main(void)
{
int i, d, rv = 0;
fputs("Enter a Number: ", stdout);
fflush(stdout);
if(scanf("%d", &d) == 1 && d >= 1) {
if(1. * d * d * d > ULLONG_MAX) {
fputs("Integer overflow\n", stderr);
rv = 1;
} else
for(i = 1; i <= d; i++)
printf("Output for %d: square %llu, cube %llu\n", i, 1ULL * i * i,
1ULL * i * i * i);
} else {
fputs("Invalid input: needed a positive integer\n", stderr);
rv = 1;
}
return rv;
}

Michael Foukarakis

unread,
Jan 11, 2010, 5:47:19 AM1/11/10
to
On Jan 10, 9:22 am, Francis Glassborow
<francis.glassbo...@btinternet.com> wrote:

> wahid wrote:
> > Write a program, that would take a number n
> > from user, and then output the square and
> > cube of first n natural numbers.
>
> > Sample Output
> > Enter a number: 5

> > Output for 1: square 1, cube 1
> > Output for 2: square 4, cube 8
> > Output for 3: square 9, cube 27
> > Output for 4: square 16, cube 64
> > Output for 5: square 25, cube 125
>
> This is the fourth problem you have posted here without any added
> material from you.
>
> Either you are an unbelievably lazy student, or you are too stupid to be
> studying programming or you are an extremely bad troll.
>

He's obviously Twink's alter ego. ;-)

Lionel Pinkhard

unread,
Jan 19, 2010, 11:01:57 AM1/19/10
to

A complete idiot could solve that!!!

natural number = try primary school mathematics, if you didn't attend primary
school, try Google or Wikipedia square/cube = ditto
take a number n from user = prompt for input, is that hard? store it as n.

The rest of the problem is simple - loop n times and use it as part of your
expression.

Don't know why I'm wasting my time trying to help in the first place.

--
--------------------------------------------------------------
Professional mobile software development
BreezySoft Limited www.breezysoft.com
--------------------------------------------------------------

Albert

unread,
Jan 20, 2010, 5:59:21 PM1/20/10
to
wahid wrote:
> � Write a program, that would take a number n

> from user, and then output the square and
> cube of first n natural numbers.
>
> Sample Output
> � Enter a number: 5
> � Output for 1: square 1, cube 1
> � Output for 2: square 4, cube 8
> � Output for 3: square 9, cube 27
> � Output for 4: square 16, cube 64
> � Output for 5: square 25, cube 125

#include <stdio.h>

int main()
{
int i, n;

printf("Enter a number: ");
scanf("%d", &n);
for (i = 1; i <= n; i++)
printf("Output for %d: square %d, cube %d\n", i, i * i, i * i * i);
return 0;
}

0 new messages