Code:
#include <stdio.h>
#include <math.h>
#include <conio.h>
int number, result;
double square_number;
int
square(int number)
{
while(number >= 0)
{
square_number = pow(2,number);
}
}
int
main(void)
{
printf("Enter an integer:");
scanf("%d", &number);
printf("\nNumber entered is: %d\n", number);
result = square(number);
while(number >= 0);
{
if(number < result)
{
printf("%d is a number less than the square of itself.\n", number);
printf("Please enter another integer:\n");
scanf("%d", &number);
}
else
{
printf("%d is a number greater than the square of itself.\n", number);
printf("Please enter another integer:");
scanf("%d", &number);
}
}
getch();
return (0);
}
Im a newbie at this, so please bare with me. This question relates to the main function. I have the following:
Code:
printf("Enter an integer:");
scanf("%d", &number);
printf("\nNumber entered is: %d\n", number);
and in the if statement, i have two alternatives, which have the code similar to above:
Code:
printf("Please enter another integer:\n");
scanf("%d", &number);
From the two examples of code, which are the same actions - ie, entering a number, is this correct? Is there a simpler way, like a call function?
Also, I have a function named square. Does it matter where I put the code? Its before the main function.