100% found this document useful (1 vote)
2 views

Practical Numerical C Programming 1st Edition Philip Joyce pdf download

The document is a promotional and informational piece about the book 'Practical Numerical C Programming' by Philip Joyce, which covers applications of C programming in finance, engineering, and physics. It includes a brief overview of the book's content, such as chapters on regression, stock price prediction, and simulations in physics, along with access to source code on GitHub. Additionally, it provides links to other related programming books and acknowledges contributions from family and the publishing team.

Uploaded by

nitkasanzivl
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2 views

Practical Numerical C Programming 1st Edition Philip Joyce pdf download

The document is a promotional and informational piece about the book 'Practical Numerical C Programming' by Philip Joyce, which covers applications of C programming in finance, engineering, and physics. It includes a brief overview of the book's content, such as chapters on regression, stock price prediction, and simulations in physics, along with access to source code on GitHub. Additionally, it provides links to other related programming books and acknowledges contributions from family and the publishing team.

Uploaded by

nitkasanzivl
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Practical Numerical C Programming 1st Edition

Philip Joyce download

https://textbookfull.com/product/practical-numerical-c-
programming-1st-edition-philip-joyce/

Download more ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

Practical Numerical C Programming: Finance,


Engineering, and Physics Applications Philip Joyce

https://textbookfull.com/product/practical-numerical-c-
programming-finance-engineering-and-physics-applications-philip-
joyce/

Java Programming Joyce Farrell

https://textbookfull.com/product/java-programming-joyce-farrell/

Java Programming Joyce Farrell

https://textbookfull.com/product/java-programming-joyce-
farrell-2/

Practical Anesthetic Management The Art of


Anesthesiology 1st Edition C. Philip Larson Jr.

https://textbookfull.com/product/practical-anesthetic-management-
the-art-of-anesthesiology-1st-edition-c-philip-larson-jr/
Visual C and Databases A Step By Step Database
Programming Tutorial 15th Edition Philip Conrod

https://textbookfull.com/product/visual-c-and-databases-a-step-
by-step-database-programming-tutorial-15th-edition-philip-conrod/

Visual C For Kids A Step by Step Computer Programming


Tutorial 15th Edition Philip Conrod

https://textbookfull.com/product/visual-c-for-kids-a-step-by-
step-computer-programming-tutorial-15th-edition-philip-conrod/

Practical System Programming with C 1st Edition Sri


Manikanta Palakollu Palakollu Sri Manikanta

https://textbookfull.com/product/practical-system-programming-
with-c-1st-edition-sri-manikanta-palakollu-palakollu-sri-
manikanta/

Learning cython programming 2nd Edition Philip Herron

https://textbookfull.com/product/learning-cython-programming-2nd-
edition-philip-herron/

Doing Right: A Practical Guide to Ethics for Medical


Trainees and Physicians 4th Edition Philip C. Hebert

https://textbookfull.com/product/doing-right-a-practical-guide-
to-ethics-for-medical-trainees-and-physicians-4th-edition-philip-
c-hebert/
Philip Joyce

Practical Numerical C Programming


Finance, Engineering, and Physics
Applications
1st ed.
Philip Joyce
Goostrey, UK

Any source code or other supplementary material referenced by the


author in this book is available to readers on GitHub via the book’s
product page, located at www.​apress.​com/​978-1-4842-6127-9. For
more detailed information, please visit http://​www.​apress.​com/​
source-code.

ISBN 978-1-4842-6127-9 e-ISBN 978-1-4842-6128-6


https://doi.org/10.1007/978-1-4842-6128-6

© Philip Joyce 2020

This work is subject to copyright. All rights are reserved by the


Publisher, whether the whole or part of the material is concerned,
specifically the rights of translation, reprinting, reuse of illustrations,
recitation, broadcasting, reproduction on microfilms or in any other
physical way, and transmission or information storage and retrieval,
electronic adaptation, computer software, or by similar or dissimilar
methodology now known or hereafter developed.

The use of general descriptive names, registered names, trademarks,


service marks, etc. in this publication does not imply, even in the
absence of a specific statement, that such names are exempt from the
relevant protective laws and regulations and therefore free for general
use.

The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.

Distributed to the book trade worldwide by Apress Media, LLC, 1 New


York Plaza, New York, NY 10004, U.S.A. Phone 1-800-SPRINGER, fax
(201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit
www.springeronline.com. Apress Media, LLC is a California LLC and the
sole member (owner) is Springer Science + Business Media Finance Inc
(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
Introduction
The C programming language is an important language in many
computer applications. It is the basis of C++ and C#. This book will
demonstrate how to use the C language to solve problems in finance,
commercial/industrial systems, and physics.
A basic familiarity with mathematics is assumed along with some
experience of the basics of computer programs.
The first chapter reviews the basic areas that C can be used in. A
more detailed introduction to C is contained in my Numerical C book.
The chapters following this C review are grouped into finance
(including regression, CAPM, and asset pricing), commercial
applications (supermarket stock control, airport flight information, and
power plant control), and various physics applications. The Graph
package has been used to display the results of programs.
There are exercises in each chapter with answers and suggested
code at the end of the book. The book’s source code can be accessed via
the Download Source Code link located at
www.apress.com/9781484261279 .
Acknowledgments
Thanks to my wife, Anne, for her support, my son Michael, and my
daughter Katharine.
Michael uses regression techniques in his work and has shared
some ideas with me.
Katharine is a software engineer working for a UK bank. All three
have mathematics degrees.
Thanks to everyone on the Apress team who helped me with the
publication of this, my second book. Special thanks to Mark Powers, the
coordinating editor, for his advice; Steve Anglin, the acquisitions editor;
Matthew Moodie, the development editor; and Juturi Narsimha Rao, the
technical reviewer.
Table of Contents
Chapter 1:​Review of C
1.​1 Arithmetic
1.​2 Switches
1.​3 Arrays
1.​4 Strings
1.​5 Mathematical Functions
1.​6 User-Written Functions
1.​7 File Creation
1.​8 File Read
1.​9 File Create2
1.​10 File Read2
1.​11 Common Mathematical and Logical Symbols
Part I: Finance Applications
Chapter 2:​Regression
2.​1 Capital Asset Pricing Model
2.​2 CAPM Illustration
Chapter 3:​PMCC
3.​1 Theory
3.​2 Manual Calculation of PMCC
3.​3 PMCC Program
3.​4 Comparison of the Two Regression Lines
3.​5 Manual Calculation of the Two Regression Lines
3.​6 Program for the Two Regression Lines
Chapter 4:​Stock Price Prediction
4.​1 Two Parts to Stock Price Changes
4.​2 Drift Part of Formula
4.​3 Simple Example with 5 Day’s Prices
4.​4 Random Change Part of Formula
4.​5 Combining the Two Elements
Part II: Commercial Applications
Chapter 5:​Supermarket Stock
5.​1 What We Are Simulating
5.​2 Updating the File
Chapter 6:​Flight Information
6.​1 Airport Display Boards
6.​2 Create Flights File
6.​3 Update Display Boards
6.​3.​1 Not-Rollup Mechanism
6.​3.​2 Rollup Mechanism
Chapter 7:​Power Plant Control
7.​1 Simulation
7.​2 Monitoring Safety Levels
Part III: Physics Applications
Chapter 8:​Energy Transfer
8.​1 Potential and Kinetic Energy Simulation
8.​2 Convert Theory to Code
Chapter 9:​Pendulum Simulation
9.​1 Pendulum Theory
9.​2 Euler Method
9.​3 Euler-Cromer Method
Chapter 10:​Center of Mass
10.​1 Center of Mass Theory
10.​2 Circular Plate
10.​3 Other Shapes
Chapter 11:​Brownian Motion
11.​1 Brownian Motion Theory
Chapter 12:​Diffusion Lattice Model
12.​1 Vacancy Lattice Diffusion
Chapter 13:​Chain Reaction
13.​1 Chain Reaction Theory
13.​2 Chain Reaction Program
Appendix:​Answers to Problems
Index
About the Author
Philip Joyce
has 28 years of experience as a software engineer – working on control
of steel production, control of oil refineries, communications software
(pre-Internet), office products (server software), and computer control
of airports. This involved programming in Assembler, COBOL, Coral66,
C, and C++. Philip was a mentor to new graduates in the company. He
also has MSc in computational physics (including augmented matrix
techniques and Monte Carlo techniques using Fortran) from Salford
University, 1996. Philip is a chartered physicist and member of the
Institute of Physics (member of the higher education group). His first
book, Numerical C, was published by Apress in September 2019.
About the Technical Reviewer
Juturi Narsimha Rao
has 9 years of experience as a software developer, lead engineer, project
engineer, and individual contributor. His current focus is on advanced
supply chain planning between the manufacturing industries and
vendors.
© Philip Joyce 2020
P. Joyce, Practical Numerical C Programming
https://doi.org/10.1007/978-1-4842-6128-6_1

1. Review of C
Philip Joyce1
(1) Goostrey, UK

This chapter reviews the properties of the C programming language.


Example programs are given to illustrate the different areas that C
covers, for example, for, while, do-while loops, user-defined functions,
switches, mathematical functions, file access, and so on.
The programs tend to bring together similar properties, for
example, mathematical functions, and incorporate them as single
programs. The reader can just use the part of these programs that they
need for their program.

1.1 Arithmetic
This program starts with the basic process of asking the user to enter
some data. Here, we will use the term “in the location c” to mean “in the
address of the variable c in the local stack space.”
Firstly, it uses the printf command to write to the user’s
command line to say “Enter character”. When the user types in a
character, the getchar function reads it and places it into the location
c. It then tells the user the character they have entered, firstly using
printf to say “Character entered” and then putchar with c as the
parameter to write the contents of c to the command line. In this case
the location c is a character location denoted by char.
If we want to read integers rather than characters, we define the
location where it is to be stored as int. In this case we call the int
this_is_a_number1. Here, we use the more widely used command
scanf to read in the integer. We specify this_is_a_number1 as a
parameter to the call, and as a first parameter, we specify %d to say that
it is an integer.
We can repeat this with another variable this_is_a_number2.
We can now add these two variables using the coding total=
this_is_a_number1+ this_is_a_number2 where total has to
be defined as an integer. Again, we can use the printf function to
display our answer from total.
We can do similar things with floating point numbers. We define
them as float rather than int. We can subtract numbers using –
rather than +. Similarly, we can multiply using * and divide using /.
The following is the code for our arithmetic calculations:

/* ch1arith.c */
/* Read, display, and arithmetic */
/* Read input data from the command line */
/* and read it into the program. */
/* Also write the data back to the */
/* command line. Basic arithmetic */
/* done on input data. */
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
int main ()
{
char c; /* Declared character variable */
int this_is_a_number1, this_is_a_number2,
total; /* Declared integer variables */
float float_number1,
float_number2,float_total; /* Declared float
variables*/

/* Read and display a character */

printf("Enter character: "); /* Tell the


user to enter a character */
c = getchar(); /* Read the character in and
store in c */

printf("Character entered: "); /* Tell the


user what was entered */
putchar(c); /* Write the char into variable
c */

/* Read in two integers, add them, and display the


answer */

printf("\nPlease enter an integer number:\n


");
scanf("%d", &this_is_a_number1); /* Read
number into this_is_a_number1 */
printf("You entered %d\n",
this_is_a_number1);

printf("Please enter another integer number:


\n");
scanf("%d", &this_is_a_number2); /* Read
number into this_is_a_number2 */
printf("You entered %d\n",
this_is_a_number2);

total = this_is_a_number1 +
this_is_a_number2; /* Add two numbers store in
total */
printf("sum of your two integer numbers is
%d\n", total); /* Write result to command line */

/* Add two floating point numbers */

printf("Please enter a decimal number:\n ");


scanf("%f", &float_number1); /* Read decimal
number into float_number1 */
printf("You entered %f\n", float_number1);
printf("Please enter another decimal number:
\n");
scanf("%f", & float_number2); /*Read decimal
number into float_number2 */
printf("You entered %f\n", float_number2);

float_total = float_number1+float_number2;
/* Add the numbers */
printf("sum of your two decimal numbers is
%f\n", float_total); /* Write result to command
line */

/* Multiply two floating point numbers */

float_total = float_number1 * float_number2;


/* Multiply the numbers */
printf("product of your two decimal numbers
is %f\n", float_total); /* Write result to command
line */

/* Divide two floating point numbers */

/* Divide the numbers */


/* Place answer into float_total */

float_total = float_number1 /
float_number2);

/* Write result to command line */

printf("quotient of your two decimal numbers


is %f\n", float_total) ;
return 0;
}

1.2 Switches
A switch statement is a multiway branch statement. A program can
perform separate different functions. In order to select which one is
required, the program asks the user to select a value, for example, 1 to
use the cosine function, 2 to use the sine function, and so on. The
program then uses this number in the switch command to jump to the
relevant code.
This sequence of code is shown as follows:

printf("\nPlease enter a character a,b,c,d or e:\n


");
scanf("%c", &this_is_a_character);/* read into
this_is_a_character */

switch (this_is_a_character)
{
case 'a':
printf("Case1: Value is: %c\n",
this_is_a_character);
break;

We can switch on numbers or characters. So, for example, we could


ask the user to enter a number from 1 to 5 or a letter from a to e. For
characters we read their value using scanf with %c as a parameter. In
the program, if you select a, then the switch jumps to case a in the
code. In the code here, we print out the fact that we have jumped to
case a, but this is only to demonstrate how it works. After the relevant
code in case a, the program issues a break which jumps to the end of
the switch options.
If the user is asked to type a to e but they type in f, then the switch
goes to the default case. Here, we can just output an error message to
the user.
The following code demonstrates switches:

/* ch1sw.c */
/* Demonstrate switch case functionality by using
switch case */
/* parameter choice as either characters or
numbers */
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

/* Example of a switch operation */


int main()
{
int this_is_a_number; /* Store area to hold
number entered */
char this_is_a_character; /* Store area to hold
character entered */

printf("\nPlease enter a character a,b,c,d or


e:\n ");
scanf("%c", &this_is_a_character); /* Read into
this_is_a_character */

/* Switch to the specific "case" for the


character entered */
/* then print which switch case was entered */
switch (this_is_a_character)
{

case 'a':
printf("Case1: Value is: %c\n",
this_is_a_character);
break;
case 'b':
printf("Case2: Value is: %c\n",
this_is_a_character);
break;
case 'c':
printf("Case3: Value is: %c\n",
this_is_a_character);
break;
case 'd':
printf("Case4: Value is: %c\n",
this_is_a_character);
break;
case 'e':
printf("Case5: Value is: %c",
this_is_a_character);
break;
default:
/* The character entered was not
between a, b, c, d, or e */
printf("Error Value is: %c\n",
this_is_a_character);
}

printf("Please enter an integer between 1


and 5:\n ");
scanf("%d", &this_is_a_number);

/* Switch to the specific "case" for the


number entered */
/* then print which switch case was
entered */
switch (this_is_a_number)
{

case 1:
printf("Case1: Value is: %d\n",
this_is_a_number);
break;
case 2:
printf("Case2: Value is: %d\n",
this_is_a_number) ;
break;
case 3:
printf("Case3: Value is: %d\n",
this_is_a_number);
break;
case 4:
printf("Case4: Value is: %d\n",
this_is_a_number);
break;
case 5:
printf("Case5: Value is: %d\n",
this_is_a_number);
break;
default:
/* The number entered was not
between 1 and 5 */
printf("Error Value is: %d",
this_is_a_number);
}

return 0;
}

1.3 Arrays
As well as defining storage locations as single int, char, or float, we
can have a number of separate values contained in the same named
location. The locations are called arrays. The following program shows
an array of 8 integers defined as int arr1[8] where arr1 is the
name we use in our program for this location.
We could now store 8 integers, for example, 53614673 in the array.
So here, arr1[0] contains 5, arr1[1] contains 3, arr1[2] contains
6, and so on. Note that we count from 0.
We can, as before, ask the user to enter data, but rather than have 8
sets of printf and scanf commands, we can use a forloop, where
we tell the program to perform the same instructions 8 times. We use
the storage location i to move from arr1[0] to arr1[1] and so on,
and we also use the i location to keep count of how many times to go
round the loop. In the for instruction for(i=0;i<8;i++), the i=0
part sets the count i to 0, the i++ adds 1 each time we loop, and i<8
limits the number of times to 8 (note again that we count from 0).
We can also have 2D arrays which are a bit like 2D matrices. We can
define an array as arr2[3][5] so we could store the matrix. The

matrix has 3 rows and 5 columns.

in our array as arr2[0][0] = 2 arr2[0][1] = 3


arr2[0][2] = 6 arr2[0][3] = 5 arr2[0][4]=10
arr2[1][0] = 4 arr2[1][1] = 12 arr2[1][2] = 7
arr2[1][3] = 8 arr2[1][4]=11
arr2[2][0] = 9 arr2[2][1] = 0 arr2[2][2] = 12
arr2[2][3] = 13 arr2[2][4]=14

Note, again, that we count from 0.


The program asks you to enter the 2D matrix. If you enter a 3x5
matrix, you can enter the data here. The program prints your array at
the end.
The code is shown as follows:

/* ch1arr.c */
/* Array use and nested forloops */

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

/* Program to show array use */

int main()
{
int arr1[8]; /* Define an array of 8 integers
*/

int arr2[3][5]; /* 2D array of integers 3 rows


and 5 columns*/

int i, j, k, l;

/* arr1 1D array */
/* Ask the user to enter the data */
printf("enter 8 integer numbers\n");

for (i = 0;i < 8;i++)


{
/* Read the data into array arr1 */
scanf("%d", &arr1[i]); /* Read into
arr1[i] */
}
printf("Your 8 numbers are \n");

for (i = 0;i < 8;i++)


{
printf("%d ", arr1[i]); /* Write contents
of arr1 to command line */
}
printf("\n");

/* arr2 2D array */

/* Ask the user to enter the data */


printf("enter number of rows and columns (max 3
rows max 5 columns) \n");
scanf("%d %d", &k, &l);
if (k > 3 || l > 5)
{
/* User tried to enter more than 3 rows
or 5 columns */
printf("error - max of 8 for rows or
columns\n");

else
{
printf("enter array\n");
/* Read i rows and j columns using nested
forloop */
for (i = 0;i < k;i++)
{
for (j = 0;j < l;j++)
{
/* Read the data into array
arr2 */
scanf("%d", &arr2[i][j]);
}
}
printf("Your array is \n");
/* Print entered 2D array using nested
forloop */
for (i = 0;i < k;i++)
{
for (j = 0;j < l;j++)
{
printf("%d ", arr2[i][j]);
}
printf("\n");

}
}

1.4 Strings
The next program shows the use of string manipulation. Strings are
char arrays in the program. Our array “select” is preset with values ‘s’ ‘e’
‘l’ ‘e’ ‘c’ ‘t’ '\0'. This is preset this way to show how the characters are
stored. We would normally define it as char select[7] = “select”;. The
second and third arrays are string1 and string2 and preset as shown.
Our first function is strlen which just returns the length of the string
you have entered. Here, it returns the length of int data point called len.
We can then print this to the user using printf.
The second string function copies one string into the other. So here,
we say strcpy(string3,string1) copies the contents of string1 into
string3. Again, we can print this out using printf.
Our next function, strcmp, compares two strings. If they are the
same, it replies 0.
Our final function concatenates one string onto the end of the other.
So here, it concatenates string2 onto string1 giving “This is string1. This
is string2”.
The code is as follows:

/* ch1strings.c */
/* Demonstrate strings */

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
/* Program to demonstrate string operations
strlen, strcpy, strcat, strcmp */

int main() {
char select[7] = { 's', 'e', 'l', 'e', 'c',
't','\0' };
char string1[32] = "This is string1";
char string2[16] = "This is string2";
char string3[16];

int len;

/* Print out the lengths of the strings */


/* strlen returns length of string */
len = strlen(string1);
printf("strlen(string1) : %d\n", len);
len = strlen(string2);
printf("strlen(string2) : %d\n", len);
len = strlen(string3);
printf("strlen(string3) : %d\n", len);

/* copy string1 into string3 */


/* strcpy copies string1 into string3 */

strcpy(string3, string1);
printf("strcpy( string3, string1) : %s\n",
string3);
len = strlen(string3);
printf("strlen(string3) after copy of
string1 into string3 : %d\n", len);

/* strcmp compares strings & returns 0 if


they are equal */
/* strcmp returns negative value if they are
not equal */
/* Compare string1 and string3 (these should
be the same)*/

if (strcmp(string1, string3) == 0)
printf("strings are the same\n");

/* Concatenates string1 and string2 */

strcat(string1, string2);
printf("strcat( string1, string2): %s\n",
string1);

/* Total length of string1 after


concatenation */
len = strlen(string1);
printf("strlen(string1) after cat of string2
onto string1 : %d\n", len);
printf("String as predefined quoted chars:
%s\n", select);

return 0;
}

1.5 Mathematical Functions


The commonly used mathematical functions are available for you to call
from your program. You need to include the library file <math.h> in
your program to access these. The first three functions are cos, sin,
and tan. Here, you are expected to enter the angle in degrees, but you
can change the code if you want so that you can enter the angle in
radians. The next three are arccos, arcsin, and arctan. Again,
these functions will return the angle in degrees, but again you can
change this to radians.
The next three functions are pow, sqrt, and fabs. The pow
function finds the power of a number. Its first parameter is the number
you want to find the power of and the second parameter is the power
you want to use. The functions return to answer to the store location
answer which is defined as a double float. The function sqrt finds
the square root of the number you enter as its parameter. Again, it
returns the answer into answer. The final function is fabs . You
supply a number as the parameter and it returns the absolute value of
the number.
The code is as follows:

/* ch1math.c */
/* Demonstrate mathematics functions */
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

#include <math.h>
#define PI 3.14159265
/* Illustration of the common trigonometric
functions */
/* also exponent, natural log, log to base 10 */
/* power, square root, and find absolute value */

int main()
{

double angle, radianno, answer;

double arccos, arcsin, arctan;


double expno, natlog, lb10;
double pownum, power, sqroot, fabsno;

/* The cosine function */

printf("cosine function:\n ");


printf("Please enter angle in degrees:\n
");
scanf("%lf", &angle);
printf("You entered %lf\n", angle);
radianno = angle * (2 * PI / 360);
answer = cos(radianno); /* returns cos
value to answer */
printf("cos of %lf is %lf\n", angle,
answer);

/* The sine function */

printf("sine function:\n ");


printf("Please enter angle in degrees:\n
");
scanf("%lf", &angle);
printf("You entered %lf\n", angle);
radianno = angle * (2 * PI / 360);
answer = sin(radianno); /* Returns sin
value to answer */
printf("sin of %lf is %lf\n", angle,
answer);
/* The tangent function */

printf("tangent function:\n ");


printf("Please enter angle in degrees:\n
");
scanf("%lf", &angle);
printf("You entered %lf\n", angle);
radianno = angle * (2 * PI / 360);
answer = tan(radianno); /* Returns tan
value to answer */
printf("tan of %lf is %lf\n", angle,
answer);

/* The arccos function */

printf("arccos function:\n ");


printf("Please enter arccos:\n ");
scanf("%lf", &arccos);
printf("You entered %lf\n", arccos);
radianno = acos(arccos); /* Returns arccos
value to radianno (in radians) */
answer = radianno * (360 / (2 * PI));
printf("arccos of %lf in degrees is %lf\n",
arccos, answer);

/* The arcsin function */

printf("arcsin function:\n ");


printf("Please enter arcsin:\n ");
scanf("%lf", &arcsin);
printf("You entered %lf\n", arcsin);
radianno = asin(arcsin); /* Returns arcsin
value to radianno (in radians) */

answer = radianno * (360 / (2 * PI));


printf("arcsin of %lf in degrees is %lf\n",
arcsin, answer);
/* The arctan function */

printf("arctan function:\n ");


printf("Please enter arctan:\n ");
scanf("%lf", &arctan);
printf("You entered %lf\n", arctan);
radianno = atan(arctan); /* Returns arctan
value to radianno (in radians) */
answer = radianno * (360 / (2 * PI));
printf("arctan of %lf in degrees is %lf\n",
arctan, answer);

/* Showing use of exp, log, and log10


functions */
/* Find exponent of entered number */

printf("exponential function:\n ");


printf("Please enter number:\n ");
scanf("%lf", &expno);
printf("You entered %lf\n", expno);

answer = exp(expno);/* returns exponent


value to answer */
printf("exponent of %lf is %lf\n", expno,
answer);

/* Find natural logarithm of entered number


*/

printf("natural logarithm function:\n ");


printf("Please enter number:\n ");
scanf("%lf", &natlog);
printf("You entered %lf\n", natlog);
answer = log(natlog); /* Returns natural
log value to answer */
printf("natural logarithm of %lf is %lf\n",
natlog, answer);
/* find log to base 10 of entered number */

printf("log to base 10 function:\n ");


printf("Please enter number:\n ");
scanf("%lf", &lb10);
printf("You entered %lf\n", lb10);
answer = log10(lb10); /* Returns log to
base 10 value to answer */

printf("log to base 10 of %lf is %lf\n",


lb10, answer);

/* Showing use of pow, sqrt, and fabs


functions */
/* Find x raised to power y number */

printf("power:\n ");
printf("Please enter number:\n ");
scanf("%lf", &pownum);
printf("You entered %lf\n", pownum);
printf("Please enter power:\n ");
scanf("%lf", &power);
printf("You entered %lf\n", power);

answer = pow(pownum, power); /* Returns


power of pownum value to answer */
printf("%lf raised to power %lf is %lf\n",
pownum, power, answer);

/* Find square root of number */

printf("square root:\n ");


printf("Please enter number:\n ");
scanf("%lf", &sqroot);
printf("You entered %lf\n", sqroot);

answer = sqrt(sqroot); /* returns square


root of sqroot value to answer */
Another Random Scribd Document
with Unrelated Content
No. 103.
LOUVOIS TO SAINT-MARS.

St. Germain, July 10th, 1680.


I have received, together with your letter of the 4th of this month,
that which was joined with it, of which I shall make the proper use.
It will be sufficient to make the prisoners in the lower part of the
tower confess once a year.
With regard to the Sieur de Lestang, I wonder at your patience,
and that you should wait for an order to treat such a rascal as he
deserves, when he is wanting in respect to you. Send me word how
it has happened that the individual named Eustache has been able
to do what you have sent me word of, and where he got the drugs
necessary for the purpose, as I cannot think you would have
furnished them to him.
De Louvois.305

305 From the Archives of France.


No. 104.
LOUVOIS TO SAINT-MARS.

Philippeville, August 16th, 1680.


I have been made acquainted, by your letter of the 7th of this
month, with the proposal you make of placing the Sieur de Lestang
with the Jacobin Monk, in order to avoid the necessity of having two
priests. The King approves of your project, and you have only to
execute it when you please.
De Louvois.306

306 Ibid.
No. 105.
SAINT-MARS TO LOUVOIS.

Matthioli and the Jacobin placed together.

September 7th, 1680.


Since you, Sir, permitted me to put Matthioli with the Jacobin in the
lower part of the tower, the aforesaid Matthioli was for four or five
days in the belief that the Jacobin was a man that I had placed with
him to watch his actions. Matthioli, who is almost as mad as the
Jacobin, walked about with long strides, with his cloak over his nose,
crying out that he was not a dupe, but that he knew more than he
would say. The Jacobin, who was always seated on his truckle bed,
with his elbows resting upon his knees, looked at him gravely,
without listening to him. The Signor Matthioli remained always
persuaded that it was a spy that had been placed with him, till he
was one day disabused, by the Jacobin’s getting down from his bed,
stark naked, and setting himself to preach, without rhyme or reason,
till he was tired. I and my lieutenants saw all their manœuvres
through a hole over the door.
De Saint-Mars.307

307 Extracted from the work of M. Roux (Fazillac).


No. 106.
SAINT-MARS TO LOUVOIS.

October 9th, 1680.


I have only further, Sir, to acquaint you with the circumstance of
the Sieur Matthioli’s having given a ring to Blainvilliers, who
immediately delivered it to me. I will keep it, till it shall please you,
Sir, to give me orders what to do with it.
I am, &c.
De Saint-Mars.308

308 Ibid.
No. 107.
SAINT-MARS TO LOUVOIS.

Particulars respecting the Ring given by Matthioli to


Blainvilliers.

October 26th, 1680.


In order to explain to you, Sir, more amply than I have hitherto
done, the story of the diamond ring which the Sieur Matthioli gave to
Blainvilliers, I shall begin by taking the liberty to tell you that I
believe he made him this present as much from fear as from any
other cause: this prisoner having previously used very violent
language to him, and written abusive sentences with charcoal on the
wall of his room, which had obliged that officer to menace him with
severe punishment, if he was not more decorous and moderate in
his language for the future. When he was put in the tower with the
Jacobin, I charged Blainvilliers to tell him, at the same time showing
him a cudgel, that it was with that the unruly were rendered
manageable, and that if he did not speedily become the latter, he
could easily be compelled to it. This message was conveyed to him,
and some days afterwards, as Blainvilliers was waiting on him at
dinner, he said to him; Sir, here is a little ring which I wish to give
you, and I beg you to accept of it. Blainvilliers replied to him that he
only took it to deliver it to me, as he could not receive any thing
himself from the prisoners. I think it is well worth fifty or sixty
pistoles.
De Saint-Mars.309

309 Extracted from the work of M. Roux (Fazillac).


No. 108.
LOUVOIS TO SAINT-MARS.

Versailles, Nov. 2d, 1680.


I havereceived your letter of the 26th of last month. I am writing
to the Sieur du Channoy to make the necessary repairs to the
barracks of the citadel of Pignerol: with regard to the brambles
which are in the walls, I think it will be better to wait till the spring
to have them rooted up, because that will make them die more
certainly, and then at the same time mortar might be inserted into
the fissures.
You must keep the ring, which the Sieur Matthioli has given to the
Sieur de Blainvilliers, in order to restore it to him, if it should ever
happen that the King ordered him to be set at liberty.
De Louvois.310

310 From the Archives of France.


No. 109.
LOUVOIS TO SAINT-MARS.

Versailles, Nov. 11th, 1680.


The King has been informed that the Governor of Milan has
received the plan of the town and citadel of Pignerol, from an
individual named Quadro, who was some time in the prison, to
explain the fortifications to one of your nephews; and as it is
important for the service of His Majesty, that the Italians should
never have any communication with the citadel of Pignerol, nor with
the prison there, His Majesty has commanded me to let you know,
that he wishes you not to allow any one to enter there, without his
express order; and his intention is, if you have any soldiers or
servants who are Piedmontese, Savoyards, or Italians, that you
should get rid of them as quietly as possible, under pretext of their
not serving you well.
De Louvois.311

311 From the Archives of France


No. 110.
LOUVOIS TO SAINT-MARS.

St. Germain, December 5th, 1680.


Your letter of the 27th of last month has reached me. The King
does not wish you to have any soldiers in your company who are
Piedmontese, Savoyards, Italians, or natives of the Government of
Pignerol. With regard to the three servants of this nation, who have
been with you for six or seven years, you may keep them, since you
are certain of their fidelity.
De Louvois.312

312 From the Archives of France.


No. 111.
LOUVOIS TO SAINT-MARS.

Appointment of Saint-Mars to the Government of Exiles—


Measures to be taken by him thereupon.

Versailles, May 12th, 1681.


I read to the King your letter of the 3d of this month, by which his
Majesty having discovered the extreme repugnance you have to
accept the command of the citadel of Pignerol, he has thought
proper to accord to you that of Exiles, vacant by the death of the
Duke of Lesdiguières; whither he wishes you to transport those of
the prisoners who are under your care, whom he shall think it
important not to entrust to any other hands but yours. I shall take
care to solicit at the office of M. de Croissy313 for the grants of the
aforesaid government, of which, as the salary does not exceed four
thousand livres, His Majesty will continue to you the five hundred
livres a month he gave you at Pignerol, by means of which your
emoluments will be as considerable as those of the Governors of the
great places in Flanders.
I have requested the Sieur du Channoy to go with you to visit the
buildings at Exiles, and to make there a list of the repairs absolutely
necessary for the lodging of the two prisoners in the lower part of
the tower, who are, I think, the only ones His Majesty will have
transferred to Exiles.
Send me a list of all the prisoners under your care, and write
opposite to each name all that you know of the reasons why they
were arrested.
With regard to the two in the lower part of the tower, you need
only designate them by this name, without adding any thing else.
The King expects that, during the little time you will be absent
from the citadel of Pignerol, when you go with the Sieur du Channoy
to Exiles, you will arrange the guarding of your prisoners in such a
manner, that no accident may happen to them, and that they may
have no intercourse with any one, any more than they have hitherto
had during the time they have been under your charge.
De Louvois.314

313 Charles Colbert, Marquis de Croissi, brother of the great Colbert,


was employed in many embassies, which he conducted with
ability and success. In 1679 he succeeded Arnaud de Pomponne
as Secretary of State for Foreign Affairs. He died in 1696.
314 From the Archives of France.
No. 112.
LOUVOIS TO SAINT-MARS.

Precautions for the Journey of the Prisoners from Pignerol


to Exiles.

Versailles, June 9th, 1681.


I send you the necessary grants, as Governor of Exiles, which the
King has thought good to have sent to you. The intention of His
Majesty is, that as soon as the room at Exiles, which you shall judge
the most proper for the secure keeping of the two prisoners in the
lower part of the tower, shall be in a state to receive them, you will
send them out of the citadel of Pignerol in a litter, and conduct them
there under the escort of your troop, for the march of whom the
orders are hereunto joined: and immediately after the departure of
the aforesaid prisoners, it is His Majesty’s intention that you should
go to Exiles, to take possession of the government, and to make it,
for the future, your residence.
And because His Majesty does not wish that the remainder of the
prisoners at present under your charge, who are to remain in the
citadel of Pignerol should be left to the care of a Captain of a
Battalion, who may be changed from day to day, I address to you an
order from the King to have the Sieur de Villebois recognized as
Commandant of the aforesaid citadel of Pignerol, until the return of
M. de Rissan, or the arrival of the person whom His Majesty shall
entrust with the command of the aforesaid citadel. In case the
health of the aforesaid Sieur de Rissan does not permit him to return
there, you will, if you please, acquaint the aforesaid Sieur de
Villebois with it, to whom the Sieur du Channoy has orders to pay
two crowns a day, for the support of those three prisoners.
You will see by the orders of the King hereunto joined, that your
company is to be reduced to forty-five men, to commence from the
15th of this month; and by the statement which accompanies them,
the footing upon which it is to be paid, as well as what the King has
ordered you for the subsistence of the two before-named prisoners,
whom His Majesty expects that you will guard with the same
exactitude you have made use of hitherto. Therefore, it only remains
for me to recommend you to give me, from time to time, intelligence
respecting them.
With regard to the effects belonging to the Sieur Matthioli, which
are in your possession, you will have them taken to Exiles, in order
to be given back to him, if ever His Majesty should order him to be
set at liberty.
You will receive the orders I have mentioned by the first occasion.
De Louvois.315

315 From the Archives of France.


No. 113.
LOUVOIS TO SAINT-MARS.

Versailles, June 11th, 1681.


I have acquainted the King with the contents of your letter of the
13th of last month, and with the list of the repairs necessary to be
made to the tower at Exiles, which you deem the most proper
residence for the prisoners whom His Majesty leaves under your
care. The King has thought fit to grant you a thousand crowns, as
well for the aforesaid repairs, as for those which you shall judge
necessary to make in your own lodging; which, as soon as you
receive this, you will take care to have done immediately, as if the
expense was to come out of your own pocket: and as soon as the
prison shall be in a fit state, it is the intention of His Majesty that
you should transfer the aforesaid two prisoners to it, according to
what I have already commanded you in my last letter; and in
conformity with that and the order which was joined to it, you will
then deliver to the Sieur de Villebois the command of the citadel of
Pignerol.
De Louvois.316

316 From the Archives of France.


No. 114.
LOUVOIS TO SAINT-MARS.

Versailles, July 9th, 1681.


I have received your letter of the 29th of last month. You may have
the doors you have need of, for the security of your prisoners, made
at Exiles, without taking the trouble of having them carried from
Pignerol.
I have written to the Père Lachaise for the benefice, which you
ask of the King for one of your children, to whom I trust His Majesty
will grant it.
De Louvois.317

317 Ibid.
No. 115.
SAINT-MARS TO LOUVOIS.

Precautions for the Security and Concealment of the


Prisoners at Exiles.

Pignerol, July 12th, 1681.


Just setting off for Exiles.
In order that the prisoners may not be seen (at Exiles,) they will
not leave their chamber when they hear mass; and in order that
they may be kept the more securely, one of my lieutenants will sleep
above them, and there will be two sentinels night and day, who will
watch the whole round of the tower, without its being possible for
them and the prisoners to see and to speak to one another, or even
to hear any thing of one another. They will be the soldiers of my
company, who will be always the sentinels over the prisoners. There
is only a confessor, about whom I have my doubts; but if you do not
disapprove, I will give them the curate of Exiles instead, who is a
good man, and very old, whom I will forbid, on the part of His
Majesty, to enquire who these prisoners are, or their names, or what
they have been, or to speak of them in any way, or to receive from
them by word of mouth, or by writing, either communications or
notes.
I am, &c.
De Saint-Mars.318

318 Extracted from the work of M. Roux (Fazillac).


No. 116.
LOUVOIS TO SAINT-MARS.

Departure of Saint-Mars from Pignerol ordered to be


deferred, in order that he might receive Catinat there.

Versailles, July 22d, 1681.


I have received your letter of the 12th of this month, by which I
see that the repairs which you have ordered to be made at Exiles
will not permit you to leave Pignerol before the end of next month.
As the service of the King will perhaps require that you should
remain there all the following month, it would be well that you
should advance the aforesaid repairs of Exiles as little as possible, in
order that you may have a pretext for not leaving Pignerol till the
first days of the month of October; taking care to act in such a
manner, that your continuing to remain there may not appear to be
the result of voluntary delay.
I am about to send the necessary order for the repayment of the
money you have expended for your prisoners, and you will receive it
by the next post.
You will find joined with this letter a packet for M. de Pianesse,319
which I request you to deliver to him without fail.
De Louvois.320

319 The Marquis de Pianesse was one of the Ministers of the Court of
Turin.
320 From the Archives of France.
No. 117.
LOUVOIS TO SAINT-MARS.

Fontainebleau, August 3d, 1681.


Your letter of the 23rd of last month has been delivered to me.
The King approves of your going to see the Marquis de Pianesse at
his country house, and of your making a journey to Turin, if you
desire it, provided you do not sleep out of the citadel of Pignerol
more than one night at a time. With regard to the journey to Exiles,
and the leave of absence you ask for the Sieur Tourtebat, whom you
wish to take with you, you will have seen by my former letters, that
the intention of the King is that you should not go there.
De Louvois.321

321 From the Archives of France.


No. 118.
LOUVOIS TO SAINT-MARS.

Orders for the Reception of Catinat at Pignerol.

Fontainebleau, August 13th, 1681.


The King having ordered M. de Catinat to go as soon as possible to
Pignerol, for the same affair which before took him there at the
commencement of the year 1679, I send you these few lines by
order of His Majesty, to give you intelligence thereof, in order that
you may prepare an apartment for him, in which he can remain
concealed for three weeks or a month; and also to tell you that
when he shall send to let you know that he is arrived at the place
where you went to meet him in the aforesaid year 1679, it is the
intention of His Majesty that you should go there again to meet him,
and that you should conduct him into the prison of the citadel of the
aforesaid Pignerol, with every kind of precaution, in order that no
one may know he is with you. I do not say any thing to you about
assisting him with your servants, your horses, and whatever
carriages he may have occasion for, because I have no doubt but
you will do with pleasure on these heads, whatever he shall ask you.
If between this time and his arrival any packet for him should be
addressed to you either from Piedmont or from Italy, you will keep
it, if you please, to deliver to him.
De Louvois.322

322 From the Archives of France.


No. 119.
LOUVOIS TO SAINT-MARS.

Fontainebleau, August 23d, 1681.


I have received your letter of the 13th of this month, which
requires no answer, except to say that I have given orders for a
French clerk to be sent, to have the direction of the Post-office at
Pignerol; by means of whom we shall be assured that no further
abuses can be committed with regard to the letters.
De Louvois.323

323 From the Archives of France.


No. 120.
LOUVOIS TO SAINT-MARS.

Fontainebleau, Sept. 20th, 1681.


This word is only for the purpose of acknowledging the receipt of
your letter of the 16th of last month. The King will not disapprove of
your visiting, from time to time, the last prisoner who has been
placed in your charge, after he shall have been established in his
new prison, and shall have left that where he is at present confined.
His Majesty desires that you will execute the order he has sent you
for your establishment at Exiles. I beg you to deliver the packet
hereunto joined into M. de Richemont’s own hands.
De Louvois.324

324 From the Archives of France. To the name of Richemont is


appended in the original the following note, in the hand-writing of
Saint-Mars; “This name means M. de Catinat, whom I had then
shut up with me at Pignerol.”
No. 121.
SAINT-MARS TO LOUVOIS.

Exiles, Dec 4th, 1681.


As there is always one of my two prisoners ill, they give me as
much occupation as I have ever had with any of those I have
hitherto guarded.
Although, Sir, you have the kindness to give me permission to go,
from time to time, to Casale, I dare not do it, lest during my
absence, you should address any packets to me for M. de Pianesse.
De Saint-Mars.325

325 Extracted from the work of M. Roux (Fazillac).


No. 122.
SAINT-MARS TO LOUVOIS.

Description of the Apartment and manner of Confinement


of the Prisoners at Exiles.

Exiles, March 11th, 1682.


Sir,
I have received the letter which you were pleased to do me the
honour to write to me on the 27th of last month, in which you
acquaint me, Sir, that it is important my two prisoners should have
no communication with any one. Since the first time that you, Sir,
gave me this order, I have guarded these two prisoners, who are
under my care, as severely and exactly as I formerly did Messieurs
Fouquet and Lauzun, who could not boast that they had either sent
or received any news, while they were in confinement. These
prisoners can hear the people speak as they pass along the road
which is at the bottom of the tower; but they, if they wished it, could
not make themselves heard; they can see the persons on the hill
which is before their windows, but cannot themselves be seen on
account of the bars which are placed across their room. There are
two sentinels of my company always night and day, on each side of
the tower, at a reasonable distance, who can see the window of the
prisoners obliquely. They are ordered to take care that no one
speaks to them, and that they do not cry out from their windows;
and to make the passengers walk on if they wish to stop in the path,
or on the side of the hill. My own room being joined to the tower,
and having no other look-out except towards this path, I hear and
see every thing, even my two sentinels, who are by this means
always kept alert.
As for the inside of the tower, I have divided it in such a manner,
that the priest who says mass to them cannot see them, on account
of a curtain I have made, which covers their double doors. The
servants, who bring their food, put whatever is necessary for the
prisoners upon a table on the outside, and my lieutenant takes it
and carries it in to them. No one speaks to them except myself, my
officer, M. Vigneron (the confessor), and physician from Pragelas,
which is six leagues from hence, who only sees them in my
presence. With regard to their linen and other necessaries, I take
the same precautions which I did with my former prisoners.
I am, &c.
De Saint-Mars.326

326 Extracted from the work of M. Roux (Fazillac).


No. 123.
SAINT-MARS TO LOUVOIS.

Exiles, Dec. 23d, 1685.


My prisoners are still ill and in a course of medicine; they are,
however, perfectly tranquil.
De Saint-Mars.327

327 Ibid.
No. 124.
SAINT-MARS TO LOUVOIS.

Saint-Mars is made Governor of the Islands of Saint


Margaret.

Exiles, January 20th, 1687.


Sir,
I am most grateful for the new favour, which I have just received
from his Majesty, (the government of the Islands of Saint Margaret).
If you order me to go there without delay, I would request to be
permitted to take the road through Piedmont, on account of the
great quantity of snow that there is between this place and Embrun;
and, on my return, which shall be as quick as I can possibly make it,
I hope you will approve of my going by the way, to take leave of the
Duke of Savoy, from whom I have always received so much
kindness. I will give such good orders for the guarding of my
prisoner, that I can answer to you, Sir, for his entire security, as well
as for his not now, nor ever, holding intercourse with my Lieutenant,
whom I have forbid to speak to him, which is punctually obeyed. If I
take him with me to the Islands, I think the most secure conveyance
will be a chair covered with oil-cloth, in which there would enter a
sufficiency of air, without its being possible for any one to see or
speak to him during the journey, not even the soldiers whom I shall
select to be near the chair. This conveyance will be less
embarrassing than a litter, which is liable often to break.
I am, &c.
De Saint-Mars.328
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like