A Bad Example Of A Loop in C
#include <stdio.h>
int number;
int i;
int main()
{
printf("\nChoose a number for the calculation: ");
scanf("%d", &number);
if (number >= 10)
{
i = number;
goto Start_Big;
}
for (i = number; i > 0; i--)
{
printf("%d to the 4th = %d", i, (i*i*i*i));
printf(", cubed = %d", (i*i*i));
Start_Big:
printf(", squared = %d", (i*i));
printf(", to the 1st = %d\n", i);
}
printf("Program Over.\n");
return 0;
}
Sample output:
Choose a number for the calculation: 4
4 to the 4th = 256, cubed = 64, squared = 16, to the 1st = 4
3 to the 4th = 81, cubed = 27, squared = 9, to the 1st = 3
2 to the 4th = 16, cubed = 8, squared = 4, to the 1st = 2
1 to the 4th = 1, cubed = 1, squared = 1, to the 1st = 1
Program Over.
This page was modified by Tanya Douglas
at: Friday, 21-Aug-2020 15:28:16 CST.
Copyright: Department of Computer Science, University of Regina of Regina.
[CS Department]