Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 1320 Basics Dr. Sajib Datta CSE@UTA.

Similar presentations


Presentation on theme: "CSE 1320 Basics Dr. Sajib Datta CSE@UTA."— Presentation transcript:

1 CSE 1320 Basics Dr. Sajib Datta

2 Course Details The website is up.
Course lectures will be uploaded there Check regularly for assignments and update

3 Programming Platform You have to execute your code on Omega server
Connect Omega Server using SSH If you are using Macbook or Linux (such as Ubuntu), then open Terminal, and commend ssh Then it will ask for password (UTA NetID password). If you are using Windows, please download SSH (Secure Sheel Client) Download Code:Blocks: Open source, cross platform, free IDE

4 Using Omega Server A Linux server Get an account!
Provides C, C++, Lisp, Prolog, Cobol, and Fortran language compilers Connect using SSH

5 Using Omega Windows users: download SSH client from OIT
Client.php

6 Connecting to Omega

7 Provide Login Information
omega.uta.edu

8 Provide Password

9 File Transfer

10 Omega Terminal

11 From MAC/Linux Applications -> Utilities -> Terminal Login:
$ ssh Logout: $ logout<Return>

12

13 Some UNIX commands ls : displays the files in a specified directory
~]$ ls rm : delete a file ~]$ rm file_name

14 Some UNIX commands mv : rename files
~]$ mv old_filename new_filename ~]$ mv old_filename directory/new_name

15 More… pwd -> print the current (working) directory
cd -> change directory cd .. ->go up one level mkdir -> make a new directory rmdir -> remove a directory Note: Commands can have options. Use man command_statement to get full details

16 Working with VI vi editor [vxg4212@omega ~]$ vi file_name.extension
Two modes: Command mode and Insert mode

17 Working with VI Insert mode: entered text is inserted into the file
Hit i to get into insert mode Hit Esc to get out of insert mode :x <Return> to exit vi Whole lot of options available in insert mode! For more on vi please visit:

18 C compiler gcc : compile a C program
~]$ gcc -o my_out program_file.c Run the compiled program ~]$ my_out<Return>

19 Introduction to C Variables, Statements, Operators, Expressions

20 Basics Storing information - Variables
Statements - Declaration, Assignment, Function Making decisions – Conditionals int num; num = 51; if (num > 25) printf(“a large class. \n”); else printf(“a small class. \n”); Repeating certain tasks – Loops Print “CSE ” 1000 times Variable declaration Assigning a value to the variable conditional Print function conditional Print function

21 Variables A variable is a symbolic name used to represent some information – data A variable is associated with a type, data storage location, its content which can be changed in running the program

22 Variables C requires the programmer to specify the type of variable.
Some examples are: int – used for integers, A number with no fractional part Never with a decimal point 3, 14, -13, 7 double – used for floating point numbers A real number including numbers between the integers 0.5, 1.234 char – used for characters, e.g., ‘A’, ‘7’, ‘?’

23 Naming a variable Lowercase letters, uppercase letters, digits,
and underscore First character must be a letter or an underscore Not key words

24 Variables Declare a variable:
int weight; int height; int weight, height; Different variable types use different amounts of memory /* reports the amount of memory occupied by an int on this hardware */ printf("an int takes %d bytes of memory\n",sizeof(int));

25 Variables Declare a variable Assign a variable a value
int height; [note that no value is still assigned] Assign a variable a value height = 5; Define - Declare & Initialize int height = 5; char name = ‘a’; double marks= 90.3;

26 Variables Print a variable Type matching
printf(“%d”, num); - format specifier, variable Number matching - the number of specifiers is equal to the number of variables Type matching %d for int %lf for double %c for char printf can be used just to print text printf(“this is just a text”);

27 Statements A C program consists of statements
Some types of statements: declaration statements Assignment statements Function calls Control statements Each statement is terminated by a semicolon. Control statement can change the program flow.

28 Declaration Declaration statements are when we declare
variables for use. void main() { int a; …… }

29 Assignment Have a left side and a right side. The right side: Example:
a single value, a complicated expression, or a function call ultimately reduce to a single value, which is then assigned to the variable named on the left side. Example: int num; [declaration] num = 1; num = num + 10; num = num + 2; [what is the final value of num?]

30 Operators The basic operators that you have in math are also available in C: +, -, *, /, = WARNING: Difference between operators in C and their math use is integer division. The fraction resulting is truncated in integer division integer = integer / integer Example: int a = 7, b = 5; int answer; answer = a / b;

31 Think! float a = 7.1, b = 5.2; int answer; answer = a / b;

32 Modulus A new operator used in C is modulus operator: %
% only used for integers, not floating-point Gives the integer remainder from integer division. Example: int a = 7, b = 3; int answer; answer = a % b;

33 More… The following assignment operators are available in C:  += addition  -= subtraction  *= multiplication  /= division  num = num + 2 same as num+=2;  num = num - 1 same as num-=1;

34 What is the output of ‘x’?
int x; x = 10; x += x; printf(“%d”, x);

35 Recap… We discussed: Omega Variable Statements Operators Data type
Declaration, assigning a value, initialization Statements Conditional statements can change the flow of the code Operators +,-,*,% Data type What happens when you assign a float/double to a variable of type int

36 Operator Precedence What is the value of x?
A precedence for each operator Multiplication and division have a higher precedence than addition and subtraction For operators with the same precedence, if they share an operand, they are executed according to the order they occur in the statement. (In most cases, from the left to the right, except assignment operation) Examples: int num, x; num = 2; x = 1 + 3*num/4; What is the value of x?

37 Operator Precedence Want an addition operation to take place before division? int num, x; num = 2; x = (1 + 3)*num/4; What is x now? int a = 1, b = 4; b += a+2; is equivalent to b = b + (a + 2)

38 Relational Operators < : is less than
<= : is less than or equal to == : is equal to >= : is greater than or equal to > : is greater than != : is not equal to Example: Relational expression: a > 10 If the relation is true, the value of the expression is 1, otherwise 0.

39 Expressions A combination of operators and operands, where operands can be constants, variables, or combinations of the two 4 4+21 a = (b+c)/2 q>4

40 Statement vs. Expression
A statement is a complete instruction to the computer In C, it is indicated by semicolon An statement is consists of expressions

41 Increment and Decrement Operator
The operand must be a variable Two varieties – prefix and postfix ++ a, --b a ++, b -- This operation increases(decreases) the value of its operand by just one! In the prefix form, the increment or decrement takes place before the value is used in expression evaluation so the value of the expression is different from the value of the operand. In the postfix form, the increment or decrement takes place after the value is used in expression evaluation so the value of the expression is the same as the value of the operand

42 Increment and Decrement Operator
Case1: a = 3; b = 2* ++a;// the value of the expression ++a is the new value of a, therefore b = ? Case2: b = 2* a++;// the value of the expression a++ is the old value of a, therefore, b = ?

43 Conditionals

44 if condition if statement gives you choice of either executing a statement or skipping it The basic format of the if statement is if (condition_is_true) do_something; // condition_is_true should be an expression //need the parenthesis for the expression // If expression evaluates to true (nonzero), do something. Otherwise, it is skipped. Normally, expression is relational expression. But in general, any expression will work since it has a value, which can be mapped to true or false.  Examples int x; int y = 6; scanf (“%d”, &x); if (x >= 2) y = 10; printf(“y is %d.\n”, y);

45 if… Examples int x; int y = 6; scanf (“%d”, &x); if (x >= 2)
printf(“y is %d.\n”, y);


Download ppt "CSE 1320 Basics Dr. Sajib Datta CSE@UTA."

Similar presentations


Ads by Google