Wednesday, 26 September 2012

Function004

Write a function to calculate the factorial value of any integer entered through the keyboard.
N.B. It will work up to nineteen number. 

#include <stdio.h>
#include <conio.h>
long       fact ( int );                                     /* Function prototype declaration */
void main ( )
{
          int         no;
          long      factorial;
          clrscr ( );
                                        
          printf("\n\n\t\t Enter a number...:"); scanf("%d", &no);
                                        
          factorial = fact ( no );                        /* Function calling */
                                      
          printf("\n\n\t\t FACTORIAL OF %d = % ld", no, factorial);
          getch ( );
}                                 
                                    
long  fact ( int    j )                                  /* Function Definition */
{                              
          int       i;
          long    f = 1;
                                   
          for ( i = 1; i <= j; i++ )
          {                                     
                          f = f * i;
          }
                                
          return ( f );
}
Click here to contact us

Tuesday, 25 September 2012

Function003

Write a function to input amount, rate, time and print simple interest.

#include <stdio.h>
#include <conio.h>
float       interest ( float, float, float );                /* Function prototype declaration */
void main ( )
{     
        float       amt, rat, tim;
        float       sud;
        clrscr ( );
                            
        printf("\n\n\t\t Enter amount.............:"); scanf("%f", &amt);
        printf("\n\n\t\t Enter rate of interest...:"); scanf("%f", &rat);
        printf("\n\n\t\t Enter time duration......:"); scanf("%f", &tim);
                                
        sud = interest ( amt, rat, tim );                       /* Function calling */
                                                         
        printf("\n\n\t\t INTEREST = % .2f", sud);
        getch ( );
}                         
                            
float  interest ( float    x, float    y, float    z )           /* Function Definition */
{                               
        float       w;
        w = ( x * z ) * y / 100.0;
        return ( w );
}
Click here to contact us

Function002

Write a function to input two numbers and print there sum and average.

#include <stdio.h>
#include <conio.h>
int        sum ( int, int );                         /* Function prototype declaration */
float     avg  ( int );                              /* Function prototype declaration */
void main ( )
{
        int           i, j, k;
        float        p;
        clrscr ( );
                  
        printf("\n\n\t\t Enter first number....:"); scanf("%d", &i);
        printf("\n\n\t\t Enter second number...:"); scanf("%d", &j);
                                      
        k = sum ( i, j );                         /* Function calling */
        p = avg ( k );                            /* Function calling */
                
        printf("\n\n\t\t SUM = %d", k);
        printf("\n\n\t\t AVERAGE = % .2f", p);
        getch ( );
}              
                
int    sum ( int    x, int    y )                /* Function Definition */
{                     
        int    z;
        z = x + y;
        return ( z );
}                                                                      
                                 
float  avg ( int    m )                         /* Function Definition */
{                  
        float    n;
        n = m / 2;
        return ( n );
}
Click here to contact us

Function001

Write a function to input two numbers and print there sum.

#include <stdio.h>
#include <conio.h>
int          sum ( int, int );                        /* Function prototype declaration */
void main ( )
{    
        int    i, j, k;
        clrscr ( );
                
        printf("\n\n\t\t Enter first number....:"); scanf("%d", &i);
        printf("\n\n\t\t Enter second number...:"); scanf("%d", &j);
                      
        k = sum ( i, j );                          /* Function calling */
                                    
        printf("\n\n\t\t SUM = %d", k);
        getch ( );
}                             
             
int     sum ( int    x, int    y )               /* Function Definition */
{          
         int    z;
         z = x + y;
         return ( z );
}
Click here to contact us

Monday, 24 September 2012

String030

Input state and print capital of that state.

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ( )
{
        char       nm[80];
        char       state[6][20] = { "WEST BENGAL", "BHIHAR", "ORISHA", "ASSAM",
                                               "GUJARAT", "RAJASTHAN" };
        char       cap[6][20] = { "kolkata", "patna", "bhubaneswar", "dispur",
                                             "gandhinagar", "jaipur" };
        int          c, i = 1;
        clrscr ( );
                     
        printf("\n\n\n\t NAME OF STATE \n\t_______________\n\t");
        for ( c = 0; c < 6; c++)
        {                                             
                     printf("\n\n\t  %s", state[c] );
        }
                                     
        printf("\n\n\n\t Enter the name of state....:"); gets(nm);
                              
        for ( c = 0; c <= 5; c++)
        {                                                   
                     if ( strcmp( nm, state[c] ) == 0 )
                     {                                    
                                    printf("\n\n\n\t Capital.....: %s", cap[c] );
                                    i = 0;
                                    break;
                     }
        }                                       
        if ( i == 1 )
        {                      
                 printf("\n\n\n\t\t NOT FOUND!");
        }
        getch ( );
}
Click here to contact us

String029

Password program.

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ( )
{
         char     masterlist[6][10] = { "akshya", "dipankar", "sanjay", "nilanjan", "sankar", "gopal" };
         char     yourname[10];
         int        i, flag = 0;
         clrscr ( );
                                 
         printf("\n\n\n\t Enter your name....:"); gets(yourname);
                         
         for ( i = 0; i <= 5; i++)
         {                              
                     if ( strcmp( yourname, masterlist[i] ) == 0 )
                     {                                     
                                    printf("\n\n\n\t\t WELCOME, YOU CAN ENTER THE PALACE!");
                                    flag = 1;
                                    break;
                     }
         }          
         if ( flag == 0 )
         {                                                       
                     printf("\n\n\n\t\t SORRY, YOU ARE A TRESPASSER!");
         }
         getch ( );
}
Click here to contact us

Sunday, 23 September 2012

String028

Input a sentence and a word, write a program to  find whether the word is in the sentence or not.

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ( )
{
          char       nm1[80], nm2[80][80], nm3[80], nm4[80] ;
          int          i = 0, j = 0, n = 0, y = 0, ln, m = 1;
          clrscr ( );
                                                      
          printf("\n\n\n\t Enter a sentence....:"); gets(nm1);
          printf("\n\n\n\t Enter a word....:"); gets(nm3);
          ln = strlen (nm1);
                                            
          for ( y = 0; y <= ln; y++ )
          {                                                   
                       if ( nm1[y] != ' ' && nm1[y] != '\0' )
                       {                                                    
                                       nm2[i][ j] = nm1[y];
                                       j++;
                       }                                              
                       else                                                 
                       {                                                     
                                       nm2[i][ j] = '\0';
                                       i++;
                                       j = 0;
                       }
          }                
          for ( j = 0; j < i; j++)
          {                                                                                 
                       n = strcmp ( nm2[ j], nm3 );
                       if ( n == 0 )   
                       {                      
                                 m = 0;
                                 break;
                       }
          }                 
          if ( m == 0 )
          {                                  
                       printf("\n\n\n\t\t WORD FOUND!");
          }                                                                 
          else                                                          
          {                                                             
                       printf("\n\n\n\t\t WORD NOT FOUND!");
          }
          getch ( );
}
Click here to contact us
Related Posts Plugin for WordPress, Blogger...