Long Integers

This is a discussion on Long Integers within the C Programming forums, part of the General Programming Boards category; Are these just regular numbers, such as 1, 2 ,3, etc.? Or are they something different? I need to make ...

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.

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.

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.

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...

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

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.

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...

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");
}