1. Long Integers

Are these just regular numbers, such as 1, 2 ,3, etc.? Or are they something different? I need to make a code that accepts two long integers, then raises one to the power of the other.

Edit:

I figured out something like this

Code:
```#include <stdio.h>
#include <math.h>

void main(void)

{
int a,b;

printf("Please Enter a Number.\t");
scanf("%d", &a);

printf("\nPlease Enter a Second Number.\t");
scanf("%d", &b);

pow(a, b);

system("Pause");

}```

but I need it to display the number. How would I do that? Also, I need to ask for someone's name, and then display it. I know it has something to do with strings, but I am not sure. Any help?

2. It's ashame you aren't using long integers.

This looks like an assignment... if it is, I'd have to say... open your book and read it. Maybe don't sleep in class tomorrow, either.

3. Unfortunately, I do not go to classes for my class. Basically I have an assignment due each week, and I am on my own to learn it. I have looked in the book, and I know that long integers are whole numbers, but have a greater range than regular integers? I am not asking anyone to do the assignment for me, but help would be appreciated.

4. Originally Posted by kabuatama
I know that long integers are whole numbers, but have a greater range than regular integers?
correct, they are also defined like so
Code:
`long a, b;`

read up on the printf statement particularly use of the %d escape sequence.

5. Here is my code so far. I got the string part to work, but am still having trouble with the exponents. What am I doing wrong?
Code:
```#include <stdio.h>
#include <math.h>

void main(void)

{
char string[256];

printf( "Please enter your name:\t " );

fgets ( string, 256, stdin );
printf("Hello, %s", string);

long a,b;

printf("Enter first number\t");
scanf("%d", &a);

printf("Enter second number\t");
scanf("%d", &b);

printf("Your total is %d\n", pow(a,b));

system("Pause");```
Do I use something other than %d for the printf section? Or does long use something entirely different? Sorry for all the questions.

6. The reason I'm ragging on you is because I feel there is no possible way your book doesn't explain this. I'm not even sure how you made it to this forum without at least at some point have come in contact with a long datatype. You're either not paying attention or you have really bad memory.

As for an answer, Quantum, pretty much gave you all you need to know. So there.

7. I am truly sorry, but I have never come across a long datatype before. My book does not explain this, so I have been checking numerous websites and the FAQs on this site to try to better understand this. Although I understand that you may be annoyed by my newbish questions, but if you could point me in the right direction, it would help me a lot.

8. As I said, Quantum told you everything you need to write the program.

9. Yes, and I wrote the program. I do not understand why I keep getting a value of "0;" it should work.

10. oh for gods sake throw him/her a bone!!! we were all n00bs once, some with better teachers than others, and some with better investigation skills than others too.

as stated, look up format specifiers. as a general rule of thumb, most functions in math.h take arguments which are doubles, and also return doubles. pow is one such function, so unless there is a requirement to use long, i would use doubles when passing arguments to pow. either is fine, you will just get a compiler warning relating to truncation. look up printf escape sequence for double...

11. couple of other things: as regurgitated ad nauseum in this forum, the return type of main is int - use it. also, that code won't compile because there is a missing brace at the end, you may not have selected all of your code when pasting it in, but in case you didnt...

also, declare all your variables at the start of the program, up where you declare your array

12. Well, my teacher wants us to use the Void Main(void), and also I did forget the last brace when I posted my code. It compiled, but I kept getting an answer of "0." Now, I figured out the long, but can only make it work while using a long double escape sequence, "%lf." Is there a way to make it work using a long integer? Finally, I have the code posted as
Code:
`long int a,b;`
,

is the int necessary? I am really sorry for asking all these questions, but it is difficult just going by the book, and I thank everyone for taking the time to help me.

13. put the int in for safety - standards and all that.

%lf is for doubles - it stands for long float (double).

to make if work with %d, when you call pow, make a cast:

(long int)pow(a,b);

14. ps. your teacher is an idiot for telling you to use void main - its non standard and although it probably works on your type of compiler, your teacher (if he/she has any professional competence) should at least explain to you that if you ever find yourselves coding under a different compiler void may/may not work...

15. It works! Thank you so much! And for the idiot teacher remark, yeah, I guess his teaching methods are a little weird. He did give us notes for this week, but the notes were on loops and if statements and conditionals. Here I am posting my code; can you just make sure everything looks correct?

Code:
```#include <stdio.h>
#include <math.h>

void main(void)

{
char string[256];
long int a,b;

printf( "Please enter your name:\t " );

fgets ( string, 256, stdin );
printf("Hello, %s\n", string);
printf("You will enter two numbers, and I will raise the first number\n");
printf("to the power of the second number!\n\n");

printf("Enter the first number.\t");
scanf("%d", &a);

printf("Enter the second number, which will be the exponent.\t");
scanf("%d", &b);

printf("Your total is %ld\n", (long int)pow(a,b));

system("Pause");

}```
Thanks again for everyone's help!

Popular pages Recent additions