Monday, August 5, 2013

Program to print all prime numbers from 1 to nth number :: logic building 6




typedef enum{false,true} bool;

void main()
{

      int inputNum;
      int count;
      int number;
      int i=0;
      bool flage = true;
     
      printf("Enter the number to print all prime numbers from 1 to :: ");
      scanf("%d",&inputNum);

      for(count = 2; count <=inputNum;count++)
      {
            i = 2;
            for(i = 2 ; i < count;i++)
            {
                  if(count%i == 0)
                  {
                        flage = false;
                       
                        break;
                  }
                 
            }
            if(flage == true)
            {
                  printf("\n%d",i);
                       
            }
            flage = true;
           
      }

      getch();

Program to enter the numbers till the user wants and at the end it should display the count of positive negative and zeros entered : Logic building(5)



      int inputNum;
      int positive = 0;
      int negative = 0;
      int Zero=0;
      int choice;

      do
      {
      printf("\nEnter the number ");
      scanf("%d",&inputNum);
     

      inputNum >= 0 ? (inputNum == 0 ? (Zero +=1) :(positive += 1)) : (negative +=1);

      printf("\nDo you want to enter more number(1/0) : ");
      scanf("%d",&choice);

      }
      while(choice==1);


      printf("\nPositive Number(s): %d \nNegative Number(s): %d \nZero(s): %d ",positive,negative,Zero);


       

Factorial , Armstrong numbers : Logic building (4)

Program to find the Factorial of a number

      int inputNum;
      int i;
      int factorial = 1;
      int value;
      printf("Please Enter Number less than or equal to 10:: ");
      scanf("%d",&inputNum);
     
      if(inputNum <= 10)
      {
      for(i =inputNum; i >= 1 ; i--)
      {
            value = i * factorial;
            printf("\n%d * %d = %d\n" , i,factorial,value);
            factorial = value;

      }
      printf("\nFactorial of %d is %d", inputNum,factorial );
      }
      else
      {
            printf("Please enter number less than or equal to 10");
      }


Program to print out all Armstrong numbers between given numbers

      int inputNum;
      int i;
      int armstrongNum ;
      int j;
      int digit;
      printf("Please Enter Number max limit");
      scanf("%d",&inputNum);

     
      for(i =1; i<= inputNum ; i++)
      {
            armstrongNum = 0;
            j = i;
            while( j > 0)
            {
                  digit = j%10;
                  armstrongNum += digit*digit*digit;
                   j = j/10;
            }
            if(armstrongNum == i)
            {
                  printf("%d\n", armstrongNum);
            }


      }

Program to find out first day of the input year : Logic building (3)


      int dayNum;
      int leapYear4, leapYear100, leapYear400;
      int inputYear;
     
      scanf("%d",&inputYear);
      leapYear4 = (inputYear - 1)/4;
      leapYear100 = (inputYear - 1)/100;
      leapYear400 = (inputYear - 1)/400;

      dayNum = (inputYear + leapYear4 - leapYear100 + leapYear400) %7;

      switch (dayNum)
      {
            case 1 :
                  printf("Monday");
                  break;
                 
            case 2 :
                  printf("Tuesday");
                  break;
            case 3 :
                 
                  printf("Wednesday");
                  break;
            case 4 :
                 
                  printf("Thursday");
                  break;
            case 5 :
                  printf("Friday");
                  break;
            case 6 :
                  printf("Saturday");
                  break;
            case 0 :
                  printf("Sunday");
                  break;
      }

Sunday, August 4, 2013

Program to determine whether the year is a leap year or not :: Logic building (2)


Before writing the program for finding Leap year, I just want to give you a brief history about the leap year and what it is.

It takes the Earth approximately 365 days, 5 hours, 48 minutes, and 46 seconds to circle once around the Sun. Leap Years are needed to keep our calendar alignment with the Earth's revolutions around the sun. So if we didn't add a day on February 29 nearly every 4 years, we would lose almost six hours off our calendar every year. After only 100 years, our calendar would be off by approximately 24 days!



To determine whether a year is a leap year or not , follow the below mentioned algorithm

Algorithm

1.       If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
2.       If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
3.       If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
4.       The year is a leap year (it has 366 days).
5.       The year is not a leap year (it has 365 days).



If the value in cell A1 is this        The formula returns
   ----------------------------------------------------------
   1992                                   Leap Year
   2000                                   Leap Year
   1900                                   NOT a Leap Year


Program to determine whether the year is a leap year or not


      int inputYear;
      printf("Please Enter Year");
      scanf("%d",&inputYear);
      if(inputYear%4 == 0)
            if(inputYear%100 == 0 )
                  {
                        if(inputYear%400 == 0)
                              printf("%d is a Leap Year",inputYear);
                              else
                              printf("%d is  not Leap Year",inputYear);}
            else
            {
                  printf("%d is Leap Year",inputYear);
            }
      else
      {
            printf("%d is not Leap Year",inputYear);


      }


Friday, August 2, 2013

Simple program :: Logic Building (1)


The below program is written in C , I think it's very easy for you guys to convert it into classic ASP.

Program to take input from the user and print a new number by adding one to each of its digits.  


void main()
{
      //Variable declaration

      int Count = 0;
      int NoOfdigits = 1;
      int InputNumber;
      int incri= 1;
      int FinalResult= 0;
      int i;

      //Taking input from the user
      printf("Enter the Number less than 10 digit ::");
      scanf("%i",&InputNumber);

      NoOfdigits = InputNumber;
     
//Calculating the length on input number
      while(NoOfdigits > 0)
      {
            NoOfdigits = NoOfdigits/10;
            Count = Count++;
           
      }
       
      //adding one in each digit of the input number
      for(i = 0 ; i < Count;i++)
      {
            FinalResult += ((InputNumber%10) +1)*incri;
            incri = incri*10;
            InputNumber = InputNumber/10;
      }

      printf("\n%d Final result after adding one in each digit ::",FinalResult);
      getch();

program to find out whether a input number is  an odd number or even number.

      int inputNumber;
      printf("Enter the number :\t");
      scanf("%d",&inputNumber);
     
      if(inputNumber >= 0)
      {
      if(inputNumber%2 == 0)
      {
            printf("Number is Even");
      }
      else
      {
            printf("Number is Odd");
      }
      }
      else
      {
            printf("Invalid Entry");

      }