Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Intro to C

Name: Anonymous 2007-10-15 5:26

What does /prog/ think of my information on number code? These are the only tools we were allowed to use plus for loops but I felt like using while when doing this.

#include <stdio.h>

int main()

{

int num;
int down;
int up;
int count;
int fix;

while (num != -9876)
        {
printf("\n-------------------------------------------------------\n\n");

printf("Enter a number to learn about or enter -9876 to quit: ");
scanf("%d", &num);
if (num == -9876)
{
return 0;
}
if (num < 0)
{
printf("\n\nPlease choose a positive number.\n\n");
}
else
{
printf("You chose the number: %d\n", num);
down = num-1;
up = num+1;
printf("The number before %d is %d\n", num, down);
printf("The number after %d is %d\n", num, up);
if (num % 2 == 0)
{
printf("%d is even.\n", num);
}
if (num % 2 != 0)
{
printf("%d is odd.\n", num);
}
count = 1;
fix = num;
printf("The next five numbers are: ");
while (count <=5)
{
count = count+1;
fix = fix+1;
printf("%d ", fix);
}
printf("\n"); 
if (num%5==0)
{
printf("%d is a multiple of five.\n", num);
}
fix = num;
fix = fix * fix;
printf("%d squared is %d.\n", num, fix);
count=0;
fix = 0;
up = 0;
while (fix <= num)
{
up = up + 1;
if ((num / (up*7)) > 0)
{
count = count + 1;
}
else
{
(fix = num + 1);
printf("Seven fits into %d %d time(s).\n", num, count); 
}
}
fix = 0;
count=0;
while (count < num)
{
    fix = fix+1;
if (fix*fix==num)
{
printf("%d is %d squared.\n", num, fix);
count=num+1;  
}
if (fix*fix>num)
{
printf("%d is not a perfect square.\n", num);
count = num + 1;
}
}
count=0;
up=1;
while (count < num)
{
up = up+1;
if (num % up == 0 && up != num)
{
printf("%d is not prime.\n", num);
count = num + 1;
}
else
{
if (up >= num)
{
printf("%d is prime.\n", num);
count = num + 1;
}
}
}      
}
}
return 0;
}

Name: Anonymous 2007-10-15 6:11

On the off chance this is real... comments in CAPS

#include <stdio.h>

int main () //USE A PROPER DECLARATION
{
  int num;
  int down;
  int up;
  int count;
  int fix;

  while (num != -9876)
  //USES NUM UNITIALIZED THE FIRST TIME
  //OTHERWISE WILL NEVER FAIL, STOP USING USELESS CONDITIONS
  {
    printf ("\n-------------------------------------------------------\n\n");

    printf ("Enter a number to learn about or enter -9876 to quit: ");
    //MERGE THE TWO PRINTFS

    scanf ("%d", &num);
    //NICE ERROR CHECKING

    if (num == -9876)
    //WHAT A FUCKING IDIOTIC END CONDITION
    {
      return 0;
      //BREAK OUT OF THE LOOP, DON'T RETURN
      //STRUCTURED PROGRAMMING MOTHERFUCKER
    }

    if (num < 0)
    {
      printf ("\n\nPlease choose a positive number.\n\n");
      //READABILITY COULD BE IMPROVED BY USING CONTINUE HERE
    }
    else
    //THAT WOULD MAKE THIS ELSE SUPERFLUOUS
    {
      printf ("You chose the number: %d\n", num);
      down = num - 1;
      up = num + 1;
      //NICE USELESS VARIABLES
      printf ("The number before %d is %d\n", num, down);
      printf ("The number after %d is %d\n", num, up);
      if (num % 2 == 0)
      {
        printf ("%d is even.\n", num);
      }
      if (num % 2 != 0)
      //MAKE THIS AN ELSE RETARD
      {
        printf ("%d is odd.\n", num);
      }

      count = 1;
      fix = num;
      //ANOTHER USELESS VARIABLE
      printf ("The next five numbers are: ");
      while (count <= 5)
      //GUESS WHY THEY INVENTED FOR LOOPS
      {
        count = count + 1;
        fix = fix + 1;
        printf ("%d ", fix);
      }
      printf ("\n");
      if (num % 5 == 0)
      {
        printf ("%d is a multiple of five.\n", num);
      }
      fix = num;
      fix = fix * fix;
      //REALLY, STOP USING TEMPORARY VARIABLES

      printf ("%d squared is %d.\n", num, fix);
      count = 0;
      fix = 0;
      up = 0;
      while (fix <= num)
      {
        up = up + 1;
        if ((num / (up * 7)) > 0)
        {
          count = count + 1;
        }
        else
        {
          (fix = num + 1);
          printf ("Seven fits into %d %d time(s).\n", num, count);
        }
      }
      //DIVISION IDIOT, USE IT

      fix = 0;
      count = 0;
      while (count < num)
      //FUCKING USELESS CONDITION, USE BREAKS
      {
        fix = fix + 1;
        if (fix * fix == num)
        {
          printf ("%d is %d squared.\n", num, fix);
          count = num + 1;
        }

        if (fix * fix > num)
        //ELSE IF MOFO
        {
          printf ("%d is not a perfect square.\n", num);
          count = num + 1;
        }
      }
      //IMPROVE THE ALGORITHM, IT LOOKS LIKE SHIT

      count = 0;
      up = 1;
      while (count < num)
      //USELESS CONDITION
      {
        up = up + 1;    //YOU REALLY NEED TO CHECK ALL EVEN NUMBERS AMIRITE
        if (num % up == 0 && up != num)
        //UP != NUM IS A USELESS CHECK
        {
          printf ("%d is not prime.\n", num);
          count = num + 1;
        }
        else
        {
          if (up >= num)
          //PUT ELSE IF ON ONE LINE
          //ALSO CHECK IF UP * UP > NUM
          {
            printf ("%d is prime.\n", num);
            count = num + 1;
          }
        }
      }
      //CHOOSE A BETTER ALGORITHM
      //OR AT LEAST MERGE IT WITH THE PREVIOUS ONE
    }
  }

  return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List