CPP Balagyruswamy : Answers
CHAPTER ONE
Addition of Two Numbers
PROGRAM USING FUNCTION
PROGRAM USING COSINE FUNCTION
Program
main( )
{
/*…………printing begins………………*/
printf(“I see, I remember”);
/*………………printing ends…………………*/
}
Addition of Two Numbers
Program
/* Programm ADDITION line-1 */
/* Written by EBG line-2 */
main() /* line-3 */
{ /* line-4 */
int number; /* line-5 */
float amount; /* line-6 */
/* line-7 */
number = 100; /* line-8 */
/* line-9 */
amount = 30.75 + 75.35; /* line-10 */
printf(“%d\n”,number); /* line-11 */
printf(“%5.2f”,amount); /* line-12 */
} /* line-13 */
INVESTMENT PROBLEM
Program
/*--------------------- INVESTMENT PROBLEM --------------------*/
#define PERIOD 10
#define PRINCIPAL 5000.00
/*-------------------- MAIN PROGRAM BEGINS --------------------*/
main()
{ /*------------------- DECLARATION STATEMENTS ----------------*/
int year;
float amount, value, inrate;
/*------------------- ASSIGNMENT STATEMENTS -------------------*/
amount = PRINCIPAL;
inrate = 0.11;
year = 0;
/*------------------ COMPUTATION STATEMENTS -------------------*/
/*--------------- COMPUTATION USING While LOOP ----------------*/
while(year <= PERIOD)
{ printf(“%2d %8.2f\n”,year, amount);
value = amount + inrate * amount;
year = year + 1;
amount = value;
}
/*----------------------- while LOOP ENDS ---------------------*/
}
/*------------------------ PROGRAM ENDS -----------------------*/
PROGRAM USING FUNCTION
Program
/*------------------- PROGRAM USING FUNCTION ------------------*/
int mul (int a, int b); /*------- DECLARATION ------------*/
/*-------------------- MAIN PROGRAM BEGINS --------------------*/
main ()
{
int a, b, c;
a = 5;
b = 10;
c = mul (a,b);
printf (“multiplication of %d and %d is %d”,a,b,c);
}
/* ---------------- MAIN PROGRAM ENDS
MUL() FUNCTION STARTS -----------------*/
int mul (int x, int y)
int p;
p = x*y;
{
return(p);
}
/* -------------------- MUL () FUNCTION ENDS ------------------*/
PROGRAM USING COSINE FUNCTION
Program
/*--------------- PROGRAM USING COSINE FUNCTION -------------- */
#include
#define PI 3.1416
#define MAX 180
main ( )
{
int angle;
float x,y;
angle = 0;
printf(“ Angle Cos(angle)\n\n”);
while(angle <= MAX)
{
x = (PI/MAX)*angle;
y = cos(x);
printf(“%15d %13.4f\n”, angle, y);
angle = angle + 10;
}
}
Be the first to comment on "CPP Balagyruswamy : Answers"