TP-02 DSP Basic Type
TP-02 DSP Basic Type
TP-02 DSP Basic Type
TP-02
Basic Data Types, Operators and Math
in C/C++
1. Data Types
char 1 %c
float 4 %f
double 8 %lf
unsigned long
at least 4 %lu
int
unsigned long
at least 8 %llu
long int
signed char 1 %c
unsigned char 1 %c
2. Operators
Arithmetic Operators
Example:
int sum1 = 100 + 50; // 150 (100 + 50)
int sum2 = sum1 + 250; // 400 (150 + 250)
Assignment operators
Example:
int x = 10;
x += 5;
Comparison operators
Example:
int x = 5;
int y = 3;
printf(x > y); //returns 1(true) because 5 is greater than 3
Logical operators
Example:
int x = 5;
int y = 3;
printf (x > y && x < 10); // returns 1 (true)
printf (x > y || x < 10); // returns 1 (true)
printf (!(x > y && x < 10)); // returns 0 (false)
3. C Math
C has many functions that allows you to perform mathematical tasks on numbers.
Example:
printf max(5, 10); // returns 10
printf min(5, 10); // returns 5
C <math.h> Header
Other functions, such as sqrt (square root), round (rounds a number)
and log (natural logarithm), can be found in the <math.h> header file:
Example:
// Include the cmath library
#include <math.h>
Function Description
expm1(x) Returns ex -1
Problem1:
Write a C program to display the following message:
--
*****************************************
** Institute of Technology of Cambodia **
*****************************************
############################################################
\\ Department of Information and Communication Engineering \\
############################################################
#########################################
// Génie Informatique et Communication //
#########################################
--
Problem2:
Write a C program to get a number from a user. Then find the square as well as the
cube of that number.
Ex:
Input: 2
Output: Square of 2 is 4 AND Cube of 2 is 8.
--
Problem3:
Write a C program that can convert the time (hour, minute, second) to second
Enter hour : 5
Enter minute : 45
Enter second : 50
=> The above time is equal to 20750 seconds.
--
Problem4:
Write a C program to convert time in second to a
time format including hour, minute and second.
Ex:
Input time in second (s) : 10000
=> It is: 2h 46mn 40s
--
Problem5:
Write a C program that can calculate some formula and display result. This program
asks a user to input x and y then compute all formula below:
f1 = 2x - 3y
f2 = 3x/2
f3 = x^3 - 5x/2 + y^(3/2)
f4 = (x + y^(1/2)) / (2x)
f5 = sin(x) + tan(y)