Wednesday 18 April 2012

How to implement Recursion algorithm using C programming language

//Green line and line having double back slash are comments
//* function within function Logic is one of the beneficial example for    recursion*/

#include stdio.h >     //preprocessor directive contain all predefine function                                   //codes

    main(void)    // Main start here
      {
          int index;
     
         index = 8;
      
         CountindexDown(index);//function call

      }  //Main Ends here



     CountindexDown( int count)  //Definition of function

        {
             count--;
                printf("The value of the count is %d\n",count);
             
             if (count > 0)
               CountDown(count);
            printf("Current value of count is %d\n",count);
        }

/*To verify the result or output paste the code in  codepad area and compile or run this*/

Tuesday 17 April 2012

C program to calculate percentile of student array



/*calculate percentile of student...i used predefined numbers and students
we can take value from user at run time  also using input fucntion*/



#include<stdio.h>
int main() 
 {
       //a[0]=obtain marks of first student 
      int a[]={25,60,80,70,26} ; 
      int n=5 ;
      int i,j ;
     //n=no. of student int percent; int count; 
        for( i=0;i<=n-1;i++) 
           { 
                count=0; 
                for(j=0;j<=n-1;j++)
                  { 
                      if(a[i]>a[j]) 
                        { 
                           count=count+1; 
                        } 
                  } 
                percent = (count * 100) / (n-1) ; //logic to calculate percentile

                printf( "\n the percentile of a[%d] is %d", i, percent) ;
            } 
 } //end of main



Calculate percentile of Students in a class using C++


/*calculate percentile of student...i did hardcode
we can get the value at run time using input fucntion*/


#include<iostream.h>
using namespace std;

int main()
{
 //a[0]=first candidate and so on
    int a[]={25,60,80,70,26},n=5,i,j;//n=no. of candidate
    int percent;
    int count;
       for( i=0;i<=n-1;i++)
         { 
             count=0;
             for(j=0;j<=n-1;j++)
               { 
                   if(a[i]>a[j])
                    {
                       count=count+1;
                    }
                }
                     percent = (count * 100) / (n-1); 
               cout << "\n the percentile of " << " a ["<<i<<"] " << percent ;
          }
 
} //End of main

/*OUTPUT:-
1-the percentile ofa[0]0
2-the percentile ofa[1]50 
3-the percentile ofa[2]100 
4-the percentile ofa[3]75 
5-the percentile ofa[4]25
*/

Friday 13 April 2012

C++ program to print decimal value of Keys appear in Keyboard


//Print decimal value of buttons appear in keyboard

#include<iostream.h> 



using namespace std;

 int main()
 { 
       int a; 
       char b; 
         for(a=0;a<=255;a++)
            { 
               b=(char)a;
               cout<<"\nASCII value of character=> "<<b<<" "<<a;
            } 
     return 0; 
}
/*:-output wiil be like:-
ASCII value of character   : 32
ASCII value of character '!' : 33 
ASCII value of character' " '   : 34 
ASCII value of character '#'  : 35 
ASCII value of character '$'  : 36 
ASCII value of character '%'  : 37 
*/


C program to print ASC|| value of character of keyboard


//C program to print ASC|| value of character of keyboard

#include<stdio.h


int main()
       int a; 
       for(a=0;a<=255;a++) 
          {
            printf("ASCII value of character %c: %d\n",a,a); 
          }
   return 0; 
}
/* OUTPUT */

C program to Concatnate two string or addition of two string

//Green lines shows they are commented
#include<stdio.h>  //header files
#include<string.h> //Header files
 
void main()  //starting of main
{
   char str1[100], str2[100];
 
   printf("Enter the first string\n");
   gets(str1);
 
   printf("Enter the second string\n");
   gets(str2);
 
   strcat(str1,str2);  //predefine function to perform concatnation
 
   printf("String obtained on concatenation is %s\n",str1);
 
} //End of main

Tuesday 3 April 2012

C program to find Factorial of a positive number

/*Green color shows that its a comment*/
/*Programme to find factorial of a number*/

#include<stdio.h>

int main()
{
          int i , facto=1,num;
        printf("Enter your number\n");
        scanf("%d",&num);
   
          for(i=1;i<=num;i++)//logic to find factorial
          {
              facto=facto*i;
          }

        printf("Factorial of %d is=>%d",num,facto);  //Print output

} //End of main program

Compiler for C,C++ and Python {paste your programme to see the output}