Simple programs

SAMPLE PROGRAM 1: PRINTING A MESSAGE


main ( )

{
   printf("I see, I remember");
   getch();
} 

Output:  I see, I remember

               A program to print one line text  

PROGRAM 2: ADDING TWO NUMBERS

main()
{
  int number;
  float amount;
  number= 100;
  
  amount = 30.75 + 75.35;
  printf("%d\n",number);
  printf("%5.2f",amount);
  getch();
}

Output:  100
                106.

                  Program to add numbers 

PROGRAM 3: INTERSEST CALCULATION
Calculate the value of money at the end of each year of investment, assuming an interest rate of 11 percent and prints the year, and the corresponding amount in two columns. The output is shown for a period of 10 years with an initial investments of 5000.00. The program uses the following formula:
Value at the end year= value at start of year(1+ interest rate)

  
#define PERIOD           10
 #define PRINCIPAL     5000.00
 main()
 {
    int year;
    float amount, value, inrate;
    amount = PRINCIPAL;
    inrate = 0.11;
    year = 0;
  
    while(year <= PERIOD)
     {  printf("%2d   %8.2f\n" ,year, amount);
           value = amount + inrate * amount;
           year = year + 1;
         amount = values;
     }
  getch();
 } 
 
  
 

No comments:

Post a Comment