1DA1117 - Computer Science, Laboratory:
Programming languages and methodology

 

Exercise 1

Write a program which allows the user to type three integer numbers and prints these numbers ordered - from the smallest to the biggest.

Use the scanf_s function for variable values reading. Syntax of scanf_s function is:

scanf_s("format", arg1, arg2, …)

scanf_s reads characters from the standard input, interprets the according to the format specified in "format" string, and stores the results in the remaining arguments, which must be a pointer.

The "format" string contains conversion specifications, similar as the printf function.

For example, the call

 

int       i;

float    x;

char    name[50];

scanf_s("%d %f %s", &i, &x, name);

 

with the input line

 

25        54.32E-1 Thomson

 

will assign the value 25 to i, the values 5.432 to x, and the string "Thomson", properly terminated by \0, to name.

 

Exercise 2

Write a program which reads from the keyboard three integer numbers – lengths of a triangle sides. The program should check whether this triangle is a right triangle and print the answer.

 

Exercise 3

Write a program which reads an integer value from the keyboard, checks whether this number is even and prints the answer.

 

 

Functions

 

Exercise 4

Write the function power(m, n) to an integer m to a positive integer power n

 

1.      Include the header file of the standard input-output

2.  Define the header of a function returning integer value and having two input integer parameters.

3. Write the ‘main’ function which reads the input parameters from the keyboard, calls the ‘power’ function and writes the result of computing.

4. Declare the ‘power’ function, which consists of the following elements:

The function returns the value of p

 

Exercise 5

Write a new version of a program which converts the temperatures for Celsius to Fahrenheit and prints the conversion table. This time however the program should make use of a function which converts the temperature values

 

Exercise 6

Modify the program in such a way that it reads the temperature value form the keyboard and writes the answer. Write the ‘main’ function in such a way that it allows the user to type several temperature values, every time followed by a conversion and printing of results. Inputting the temperature ‘-99999’ should end the program.

 

References

1.      Brian W. Kernighan, Dennis M. Ritchie. The C Programming Language, Second Edition, Prentice Hall, Inc., 1988. (Polish edition: „Język Ansi C. Programowania. Wydanie II”, Wydawnictwo Helion, 2010) http://s3-us-west-2.amazonaws.com/belllabs-microsite-dritchie/cbook/index.html  

2.      Scott E. Gimpel, Clovis L. Tondo. The C Answer Book, Prentice Hall, Inc., 1988. (Polish edition: “Język Ansi C. Programowanie. Ćwiczenia. Wydanie II”,  Helion, 2010)