Saturday, 15 March 2014

C Program Calculation of bonus

/* Calculation of bonus */
main( )
{
int   bonus, cy, yoj, yr_of_ser ;
printf ( "Enter current year and year of joining " ) ;
scanf ( "%d %d", &cy, &yoj ) ;
yr_of_ser = cy - yoj ;
if ( yr_of_ser > 3 )
{
bonus = 2500 ;
printf ( "Bonus = Rs. %d", bonus ) ;
}
}

C Program for File encryption utility

/* File encryption utility */
#include "stdio.h"
main( )
{
encrypt( ) ;
}
encrypt( )
{
FILE  *fs, *ft ;
char   ch ;
fs = fopen ( "SOURCE.C", "r" ) ;  /* normal file */
ft = fopen ( "TARGET.C”, "w" ) ;  /* encrypted file */
if ( fs == NULL || ft == NULL )
{
printf ( "\nFile opening error!" ) ;
exit ( 1 ) ;
}
while ( ( ch = getc ( fs ) ) != EOF )
  putc ( ~ch, ft ) ;
fclose ( fs ) ;
fclose ( ft ) ;
}

C Program Demonstration of call by value

/* Demonstration of call by value */
main( )
{
int  i ;
int  marks[ ] = { 55, 65, 75, 56, 78, 78, 90 } ;
for ( i = 0 ; i <= 6 ; i++ )
display ( marks[i] ) ;
}
display ( int  m )
{
printf ( "%d ", m ) ;
}

C Program Calculation of total expenses

/* Calculation of total expenses */
main( )
{
int   qty, dis = 0 ;
float   rate, tot ;
printf ( "Enter quantity and rate " ) ;
scanf ( "%d %f", &qty, &rate) ;
if ( qty > 1000 )
dis = 10 ;
tot = ( qty * rate ) - ( qty * rate * dis / 100 ) ;
printf ( "Total expenses = Rs. %f", tot ) ;
}

C Program Display contents of a file on screen.I

#include <stdio.h>
main ( int  argc, char  *argv[ ] )
{
FILE  *fs, *ft ;
char  ch ;
if ( argc != 3 )
{
puts ( "Improper number of arguments" ) ;
exit( ) ;
}
fs = fopen ( argv[1], "r" ) ;
if ( fs == NULL )
{
puts ( "Cannot open source file" ) ;
exit( ) ;
}
ft = fopen ( argv[2], "w" ) ;
if ( ft == NULL )
{
puts ( "Cannot open target file" ) ;
fclose ( fs ) ;
exit( ) ;
}
while ( 1 )
{
ch = fgetc ( fs ) ;
if ( ch == EOF )
break ;
else
fputc ( ch, ft ) ;
}
fclose ( fs ) ;
fclose ( ft ) ;
}