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
There's a novel idea, why don't you give it a try?
--
Ian Collins
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.
#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;
}
He's obviously Twink's alter ego. ;-)
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
--------------------------------------------------------------
#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;
}