Showing posts with label algorithm. Show all posts
Showing posts with label algorithm. Show all posts

Wednesday, 8 August 2018

Algorithm to find factorial of input number from user in C language

Program To Find Factorial Of Any Number in " C" Language

/* factorial of a number */
# include <stdio.h>
void main ()
{
int a ;
fact = 1;
clrscr () ;
printf ("\n enter a number:") ;
scanf ("%d", & a) ;
while ( a!=0 )
{
fact = fact*a ;
a-- ;
}
printf ("\n factorial of %d =%d", a,fact) ;
getch () ;
}

Output in c :

Enter a number : 4
factorial : 4 * 3 * 2 * 1 = 24
Enter a number : 6
factorial : 6 * 5 * 4 * 3 * 2 * 1 = 720

ALGORITHM :  TO FIND FACTORIAL OF A NUMBER INPUT FROM USER IN C

                         This is a program for calculation of factorial of a number input from user in c.

STEP 1. START.
STEP 2. SET FACT = 1.
STEP 3. INPUT A NUMBER SAY A.
STEP 4. { CHECK FOR CONDITION }
               A ! = 0.
            { HERE A ! = 0 BECAUSE FACTORIAL IS ALWAYS MULTIPLE OF MAXIMUM OF THE GIVEN NUMBER TO ONE}
STEP 5. FACT = FACT * A.
STEP 6. A = A - 1.
STEP 7. PRINT VALUE OF FACT.
STEP 8. STOP.

                     

Monday, 6 August 2018

Algorithm To Displays Color According To The Enter Character From User in C

Program To Displays Color According To The Enter Character From User in C

/*program to print color*/
# include <stdio.h>
void main ()
{
char ch ;
clrscr () ;
printf ("/n enter a character :") ;
scanf ("%c", & ch) ;
switch (ch)
{
case 'r' ;
printf ("\n colour is red :") ;
break ;
case 'w' ;
printf ("\n color is white :") ;
break ;
case 'y' ;
printf ("\n color is yellow :") ;
break ;
case 'g' ;
printf ("\n color is green :") ;
break ;
case 'b' ;
printf ("\n color is blue :") ;
break ;
default :
printf ("\n invalid character :") ;
}
getch () ;
}

Algorithm To Displays Color According To The Enter Character From User in C

ALGORITHM :: DISPLAY COLOR AFTER INPUT CHARACTER FROM USER.

This is program to input a character from user and display color.

STEP 1. START.
STEP 2. INPUT A.
STEP 3. { DISPLAY COLOR }
             
              1. IF ENTER WORD IS R.
              2. DISPLAY COLOR IS " RED ".
              3. IF ENTER WORD IS W.
              4. DISPLAY COLOR IS " WHITE " .
              5. IF ENTER WORD IS Y.
              6. DISPLAY COLOR IS " YELLOW ".
              7. IF ENTER WORD IS G.
              8. DISPLAY COLOR IS " GREEN ".
              9. IF ENTER WORD IS B.
              10. DISPLAY COLOR IS " BLUE "

OTHERWISE
11. PRINT " INVALID CHARACTER " .
STEP 4. STOP





Algorithm with the help of program to find out even or odd In C

Program to Check Number is Even or Odd

Here we are going to write program to check enter  number is even or odd . We have to know about operator used in C which is most important for applying condition in the program . On the previous blog I told you about operator used in C so please read from there . For writing program to check number is even or odd. As we know that even number are those number which are exactly divisible by 2 and odd number are those which are not divisible by 2. Now we are going to write program.

/*program to check no.is even or odd*/
#include <stdio.h>
void main()
{
int a;
clrscr ();
printf ("/n Enter a number:");
scanf ("%d", & a);
if ( a%2==0)
printf ("/n a is even number:");
else 
printf ("/n a is odd number :");
getch();
}

From written program you seen that first of all we have to enter a number from the user and then we have used condition for checking. A even number is divisible by 2 then it must gives 0 as remainder then print number is even otherwise it will we odd number. Please comment for any issue in this program for spreading information.

Algorithm to find out even or odd :

Now we are going to write algorithm for this program as we discuss earlier algorithm is step by step representation of program. Algorithm is generally out in capital letter and always start with START and end with STOP. In C programming 
language it is very important to write algorithm.

ALGORITHM : CHECK NUMBER IS EVEN OR ODD.

                           This is a program to input a number and check input number is even or odd.

STEP 1. START.
STEP 2. INPUT A NUMBER.
STEP 3. { CHECK NUMBER IS EVEN OR ODD }

1. IF A IS DIVISIBLE BY 2.
2. PRINT  " A IS EVEN ".
3. OTHERWISE.
4, PRINT " A IS ODD".

       { END OF LOOP 3 }
STEP 4. STOP.




Saturday, 4 August 2018

Algorithm for finding maximum of three number in C.

Program To Find Maximum Of Three Number Using 'If else' Statement

/*program to find maximum of 3 number*/
#include <stdio.h>
void main ()
{
int a,b,c;
clrscr ();
printf ("/n Enter value of a :");
scanf ("%d", & a);
printf ("/n Enter value of b :");
scanf ("%d", & b);
printf ("/n Enter value of c :");
scanf ("%d", & c);
if ((a>>b)&&(a>>c))
printf ("/n a is maximum number:");
else if ((b>>a)&&(b>>c))
printf ("/n b is maximum number:");
else
printf ("/n c is maximum number:");
getch ();
}

OUTPUT :

                    Enter value of a : 45
                    Enter value of b : 55
                    Enter value of c : 65

65 is the greatest number.

ALGORITHM :: MAXIMUM OF THREE NUMBER ( A , B AND C )

This algorithm is used to determined the maximum of three number say ( a , b , c )

STEP 1. START.
STEP 2. INPUT A , B AND C.
STEP 3. [ MAXIMUM OF THREE NUMBER A , B AND C ]

              1. IF A IS GREATER THAN B AND A IS ALSO GREATER THAN C.
              2. PRINT " A IS MAXIMUM ".
              3. IF B IS GREATER THAN A AND B IS ALSO GREATER THAN C.
              4. PRINT " B IS MAXIMUM ".
              5. IF C IS GREATER THAN A AND C IS ALSO GREATER THAN B.
              6. PRINT " C IS MAXIMUM ".

                [ END OF LOOP 3 ]

STEP 4. STOP






Friday, 3 August 2018

Algorithm to check Input Character Check is Vowel or Consonant in C


Program To Input a Character From User And Check Enter Character Is Vowel or Consonant

/*program character is c or v*/
#include <stdio.h>
void main ()
{
char ch ;
clrscr () ;
printf ("/n Enter a character:") ;
scanf ("%c", & ch) ;
switch (ch)
{
case 'a';
printf ("/n vowel:") ;
break ;
case 'e';
printf ("/n vowel:") ;
break ;
case 'i';
printf ("/n vowel:") ;
break ;
case 'o';
printf ("/n vowel:") ;
break ;
case 'u';
printf ("/n vowel:") ;
break ;
default :
printf ("/n character is consonant:") ;
}
getch () ;
}

Output :: Enter a character :  a

                   Character is vowel
                 
                   Enter a character :   z
     
                  character is consonant 

ALGORITHM :: 

                                CHECK INPUT CHARACTER IS VOWEL OR CONSONANT

This is a program of having to check input character is vowel or consonant .

STEP 1. START.
STEP 2. INPUT A CHARACTER.
STEP 3. [ CHECK VOWEL OR CONSONANT ]
                1. IF ENTER CHARACTER IS A , E , I . O , U ]
                2. PRINT CHARACTER IS VOWEL.
                3. OTHERWISE.
                4. PRINT CHARACTER IS CONSONANT.
             [ STEP LOOP 3 IS END ]
STEP 4. STOP.

Thursday, 2 August 2018

ALGORITHM OF CALCULATION OF ADDITION , SUB , MULTI , DIV OF A AND B IN C

Program To Input Two Number From User And Calculate Add,Sum,Multi,and Div Of The Number According To The Choice

/*program of menu driven program*//
# include <stdio.h>
void main ()
{
int a,b,c,choice ;
clrscr () ;
printf ("/n enter the first number :") ;
scanf ("%d", & a) ;
printf ("/n enter second number :");
scanf ("%d", & b) ;
printf ("/n you can perform the following operation :") ;
printf ("/n 1.addition :") ;
printf ("/n 2.subtraction :") ;
printf ("/n 3. multiplication :") ;
printf ("/n 4. division :") ;
printf ("/n enter your choice :") ;
scanf ("%d", & choice) ;
switch (choice)
{
case 1 ;
c= a+b ;
printf ("/n sum = %d", c) ;
break ;
case 2 ;
c= a-b ;
printf ("/n sub = %d", c) ;
break ;
case 3 ;
c= a*b ;
printf ("/n multi = %d", c) ;
break ;
case 4 ;
c= a\b ;
printf ("/n div = %d". c) ;
break ;
default :
printf ("/n invalid number :") ;
}
getch () ;
}
Output :: enter the first number :
                number is : 45
                enter second number 
                 number is : 35

c = 45 + 35 = 80   ( if choice is 1 )
c = 45 - 35 = 10     ( if choice is 2 )
c = 45 * 35 = 1575  ( if choice is 3 )
c = 45 / 35 = 1.2      ( if choice is 4 )

ALGORITHM : CALCULATE ADDITION , SUB , MULTI , DIV OF A AND B

This is program of having calculation according to the choice of user.

STEP 1. START.
STEP 2. INPUT A AND B AND THEN CHOICE.
STEP 3. [ CALCULATE ADDITION , SUB , MULTI , DIV OF A AND B ]
              
              1. IF ENTER CHOICE IS 1.
               2. PRINT " C = A + B ".
               3. IF ENTER CHOICE IS 2.
               4. PRINT " C = A - B ".
               5. IF ENTER CHOICE IS 3.
               6. PRINT " C = A * B ".
               7. IF ENTER CHOICE IS 4.
               8. PRINT " C = A / B ".

OTHERWISE

9. PRINT " INVALID CHOICE".
        { STEP 3 LOOP 9 IS END }
STEP 4. STOP




                











              


Wednesday, 1 August 2018

Algorithm of Fibonacci series in c



Program to print n terms of fibonacci series in c


/* program to print fibo series */
#include <stdio.h>
void main ()
{
int a=0,b=1,sum,counter=0,n ;
clrscr () ;
printf ("/n %d",a) ;
printf ("/n %d",b) ;
printf ("/n how many terms you want to print:") ;
scanf ("%d", & n) ;
while (counter<n-2)
{
sum=a+b ;
printf ("/n %d",sum) ;
a=b ;
b=sum ;
counter++ ;
}
getch () ;
}

Output :

How many terms you want to print : 5
number are : 0 , 1 , 1 , 2 , 3.

Algorithm ;;

ALGORITHM : FIBONACCI SERIES ( A , B , N , COUNTER )

This algorithm is used to print n terms of fibonacci series 

STEP 1. START.
STEP 2. SET A = 0 , B = 1 , COUNTER = 0 .
STEP 3. INPUT N.
STEP 4. WRITE A.
STEP 5. WRITE B.
STEP 6. REPEAT STEP 7 TO 11.
                  COUNTER < N -2
               [ N - 2 IS WRITTEN BECAUSE OF PRINTING FIRST TWO TERMS OUT OF LOOP ]
STEP 7. SUM : = A + B.
STEP 8. PRINT SUM.
STEP 9. SET A : = B.
STEP 10. SET B : = SUM.
STEP 11. [ INCREMENT THE VALUE OF COUNTER BY 1 ]
                  COUNTER : = COUNTER + 1.
STEP 12. STOP.



Featured post

Kalgudi Interview Round!!

Those who cleared the second round of kalgudi got an email from exceller to complete their Kalgudi Interview Round. So here we will discuss ...