How to Waste Your Time While Programming


Fun ways to kill off coding productivity:

  • Use lots of spaces.
  • Align code in arbitrary places.
  • Make up really long variable and function names.
  • Make up random variable and function names.
  • Rewrite the same functions a dozen or so times.
  • Guess, write some code, toss and then guess again…
  • Stand around in meetings every day.
  • Sit around in meetings every day.
  • Procrastinate about getting organized.
  • Get clever (monkeys are clever …)
  • Comment the obvious aspects of the code.
  • Apply a hastily thought-out patch.
  • Add in extra lines of code in the hopes that somehow, that will make it better.
  • Change everything at the last moment.
  • Continuously ignore a serious problem or miscommunication.
  • Watch someone else type.
  • Write a test for something that would be obvious if it were wrong.
  • Write a test for something that ain’t never going to happen.
  • Re-invent something that has been in textbooks for decades.
  • Rely on something that kinda works, instead of spending the time to build something that actually works.
  • Take technical advice from non-programmers.
  • Ignore domain or usability complaints from the users.
  • Assume (pretty much anything).
  • Believe in the marketing documentation, without reading the specs first.
  • Design an ugly user interface (and refuse to believe that it is ugly).
  • Write documentation that absolutely nobody will read and if they did, couldn’t glean any useful information from.
  • Make pretty diagrams. Lots and lots of pretty diagrams.
  • Build something large without a design or blueprints.
  • Build something small and expect it to magically grow into something large.
  • Provide too much information(s).
  • Wait for the magic to happen.
  • Ignore what every else is doing, and get super, super, super creative.

I’m sure there are lots more …

C PROGRAM TO PRINT ALL PERFECT NUMBERS BETWEEN 1 AND 100


#include <stdio.h>
#include<conio.h>
main()
{
    int n = 100,sum = 0;
    printf(” to print all the perfect no. between 1 and 100″);
    for(int num=1;num <=n;num++)
    {
            sum = 0;
            for(int i = 1; i < num; i++)
            {
            if(!(num%i))
            {
            sum+=i;
            }
            }
            if(sum == num)
            printf(“%d is a perfect number”,num);
  }
  getch();
}

C PROGRAM TO CHECK A NO. IS PERFECT OR NOT


#include<stdio.h>
#include<conio.h>

main()
{
      int n,i=1,sum=0;
      printf(“\nEnter a number:-“);
      scanf(“%d”,&n);
      while(i<n)
      {
                if(n%i==0)
                sum=sum+i;
                i++;
      }
      if(sum==n)
      printf(“\nThe no %d is a perfect number”,i);
      else
      printf(“\nThe no %d is not a perfect number”,i);
      getch();
}

C PROGRAM TO FIND MEAN, MEDIAN, AND MODE FOR DIFFERENT CASES


#include <iostream.h>
#include <conio.h>
double GetMedian(double daArray[], int iSize) {
    // Allocate an array of the same size and sort it.
    double* dpSorted = new double[iSize];
    for (int i = 0; i < iSize; ++i) {
        dpSorted[i] = daArray[i];
    }
    for (int i = iSize – 1; i > 0; –i) {
        for (int j = 0; j < i; ++j) {
            if (dpSorted[j] > dpSorted[j+1]) {
                double dTemp = dpSorted[j];
                dpSorted[j] = dpSorted[j+1];
                dpSorted[j+1] = dTemp;
            }
        }
    }

    // Middle or average of middle values in the sorted array.
    double dMedian = 0.0;
    if ((iSize % 2) == 0) {
        dMedian = (dpSorted[iSize/2] + dpSorted[(iSize/2) – 1])/2.0;
    } else {
        dMedian = dpSorted[iSize/2];
    }
    delete [] dpSorted;
    return dMedian;
}

double GetMode(double daArray[], int iSize) {
    // Allocate an int array of the same size to hold the
    // repetition count
    int* ipRepetition = new int[iSize];
    for (int i = 0; i < iSize; ++i) {
        ipRepetition[i] = 0;
        int j = 0;
        bool bFound = false;
        while ((j < i) && (daArray[i] != daArray[j])) {
            if (daArray[i] != daArray[j]) {
                ++j;
            }
        }
        ++(ipRepetition[j]);
    }
    int iMaxRepeat = 0;
    for (int i = 1; i < iSize; ++i) {
        if (ipRepetition[i] > ipRepetition[iMaxRepeat]) {
            iMaxRepeat = i;
        }
    }
    delete [] ipRepetition;
    return daArray[iMaxRepeat];
}

double GetMean(double daArray[], int iSize) {
    double dSum = daArray[0];
    for (int i = 1; i < iSize; ++i) {
        dSum += daArray[i];
    }
    return dSum/iSize;
}

main()
{
    int t;
    double dValues[50];
    std::cout<<“\nEnter the no. of test cases:-\n”;
    cin>>t;
    std::cout<<“\nenter the elements:-\n”;
    for(int i=0;i<t;i++)
    cin>>dValues[i];
    int iArraySize =t;

    std::cout << “Median = “
                << GetMedian(dValues, iArraySize) << std::endl;
    std::cout << “Mode = “
                << GetMode(dValues, iArraySize) << std::endl;
    std::cout << “Mean = “
                << GetMean(dValues, iArraySize) << std::endl;

    getch();
}

C PROGRAM TO PRINT ABC TRIANGLE PATTERN


#include <stdio.h>
#include<conio.h>
main()
      {
      int i, j, k;
      char ch;

      i = 0;
      while(i <= 5)
      {
      j = 5;
      ch = ‘A’;
     
      printf(“\n”);
      while(j >= i)
      {
              printf(“%c”, ch);
              j–;
              ch++;
              }   
              j = 1;
                while(j <= (2 * i – 1))
                {
                        printf(“-“);
                        j++;
                        }
                        if(i == 0)
                        ch -= 2;
                        else ch–;
                             while(ch >= ‘A’)
                             {
                             printf(“%c”, ch);
                             ch–;
                             }
                             i++;
                             }
                             getch();
}

C PROGRAM TO PRINT THE FREQUENCY OF CHARECTERS ENTERED BY THE USER


#include<stdio.h>
#include<conio.h>
#include<string.h>

main()
{
   char string[50], ch;
   int i, num[26], length;

   printf(“Enter a string “);
   gets(string);
   strlwr(string);

   for ( i = 0 ; i < 26 ; i++ )
      num[i] = 0;

   length = strlen(string);

   for ( i = 0 ; i < length ; i++ )
   {
      for (ch = ‘a’ ; ch <= ‘z’ ; ch++ )
      {
         if ( string[i] == ch )
            num[ch-97]++;
      }
   }

      for ( i = 0 ; i < 26 ; i++ )
      printf(“\n\t occurances of ”%2c” in the entered string is =%d “,i+97,num[i]);

   getch();
  
}