Review (before the 1 st test): while (conditions) { statements; } while loop: if/else if/else statements: if (conditions) { statements; } else if (different.

Slides:



Advertisements
Similar presentations
#include void main() { float x = 1.66, y = 1.75; printf(%f%f,ceil(x), floor(y)); }
Advertisements

Sort the given string, without using string handling functions.
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
1 Introduction to Computing: Lecture 16 Character Strings Dr. Bekir KARLIK Yasar University Department of Computer Engineering
Selection Statements Selects statements to execute based on the value of an expression The expression is sometimes called the controlling expression Selection.
1 Introduction to Computing Lecture 11 Character Strings Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical&Electronics Engineering
C workshop #3 flow control / strings.
1 Review of Class on Oct Outline of Chapter 4  How to write a function?  Function Prototypes  Function Invocation  Function Definition  The.
Introduction to Computers and Programming Class 15 Introduction to C Professor Avi Rosenfeld.
C. About the Crash Course Cover sufficient C for simple programs: variables and statements control functions arrays and strings pointers Slides and captured.
1 CSE1301 Computer Programming: Lecture 19 Character Strings.
C Programming Strings. Array of characters – most common type of array in C  Let’s make them easier for use Denote the end of array using a special character.
A simple C program: Printing a line of text #include main() { printf(“hello, world\n”); } Program output: hello, world.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
Computer Science 210 Computer Organization Introduction to C.
Strlen() implementation /* strlen : return length of string s */ int strlen(char *s) { int n; for (n = 0 ; s[n] != ‘\0’ ; n++) ; return n; } /* strlen.
POINTERS. 1.a) POINTER EXPRESSIONS Pointer variables can be used in expression If p1 and p2 are properly declared and initialized pointers then following.
STRING Dong-Chul Kim BioMeCIS UTA 10/7/
The char Data Type A char is a one byte integer type typically used for storing characters. Example: char oneLetter = ’D’; We enclose the character in.
Lecture 10: Reviews. Control Structures All C programs written in term of 3 control structures Sequence structures Programs executed sequentially by default.
Principles of Programming - NI July Chapter 5: Structured Programming In this chapter you will learn about: Sequential structure Selection structure.
#include int main(void) { printf("Hello, world!\n"); return 0; } entry point called on program start only one main( ) in any program # for preprocessor.
 2000 Prentice Hall, Inc. All rights reserved Arrays Array –Group of consecutive memory locations –Same name and type To refer to an element, specify.
Introduction to C Programming CE Lecture 4 Further Control Structures in C.
CS140: Intro to CS An Overview of Programming in C (part 3) by Erin Chambers.
Chapter 5: Structured Programming
COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez
C Programming Lecture 7 : Control Structures. Control Structures Conditional statement : if, switch Determine a block of statements to execute depending.
Lecture 22: Reviews for Exam 2. Functions Arrays Pointers Strings C Files.
CSCI 171 Presentation 5. The while loop Executes a block as long as the condition is true general form: while (condition) { statement 1; statement 2;
Selection-making Decisions Selection allows you to choose between two or more possible program flow --- it lets you make decisions in your program. Examples.
Khalid Rasheed Shaikh Computer Programming Theory 1.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 21 Thanks for Lecture Slides:
Lecture 13: Arrays, Pointers, Code examples B Burlingame 2 Dec 2015.
UNIT 11 Random Numbers.
Pointers and Arrays An array's name is a constant whose value is the address of the array's first element. For this reason, the value of an array's name.
BY ILTAF MEHDI (MCS, MCSE, CCNA)1. INSTRUCTOR: ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) BY ILTAF MEHDI (MCS, MCSE, CCNA)2 Chapter No: 04 “Loops”
1 Pointers: Parameter Passing and Return. 2 Passing Pointers to a Function Pointers are often passed to a function as arguments  Allows data items within.
LOOPING IN C. What would be the output of the following program main( ) { int j ; while ( j
Dr. Sajib Datta Feb 21,  In the last class we discussed: ◦ Bubble sort  How it works  performance.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Introduction to Programming Lecture 5: Interaction.
Principles of Programming - NI Chapter 10: Character & String : In this chapter, you’ll learn about; Fundamentals of Strings and Characters The difference.
Pointers. Pointer Arithmetic Since arrays consist of contiguous memory locations, we can increment (or decrement) the addresses to move through the array.
Dynamic memory allocation and Intraprogram Communication.
Characters must also be encoded in binary. ASCII maps characters to numbers.
Dr. Sajib Datta Sep 8,  char type technically is an integer type  Computer uses numeric codes to represent characters, and store characters.
Chapter 5: Structured Programming
Chapter 8 Arrays, Strings and Pointers
Computer Science 210 Computer Organization
- Standard C Statements
Decisions Chapter 4.
Lecture 8 String 1. Concept of strings String and pointers
Review of C… The basics of C scanf/printf if/elseif statements
Week 4 – Repetition Structures / Loops
FUNCTIONS.
CS1010 Programming Methodology
מחרוזות קרן כליף.
Dynamic memory allocation and Intraprogram Communication
توابع ورودي-خروجي.
INC 161 , CPE 100 Computer Programming
Chapter 8 The Loops By: Mr. Baha Hanene.
CSC215 Homework Homework 03 Due date: Oct 07, 2016.
Relational, Logical, and Equality Operators
EECE.2160 ECE Application Programming
Character Arrays char string1[] = “first”;
Strings #include <stdio.h>
Iteration Statement for
Presentation transcript:

Review (before the 1 st test): while (conditions) { statements; } while loop: if/else if/else statements: if (conditions) { statements; } else if (different conditions) { statements; } else { statements; } while (conditions) { statements; while (conditions) { statements; } statements; } Nested while statements: for (initialization; conditions; increment) { statements; } for loop:

Reminder on functions: int function(int a, int b); /* function prototype */ int main() { int functionvalue, num1, num2; functionvalue = function(num1, num2); /* call the function */ } int function(int num1, int num2) /* the function */ { int returnvariable; returnvariable = perform actions; return returnvariable; }

Reminder on functions, another example: void function(int a, float b); /* function prototype */ int main() { int num1; float num2; function(num1, num2); /* call the function */ } void function(int num1, float num2) /* the function */ { perform actions; }

This calculates the average! #include int main(void) { int num[9] = {10,20,30,40,50,60,70,80,90}; int calc=0, i; for (i=0;i<9;i++) { calc = calc+num[i]; } calc = calc/9; printf(“calc = %d\n”, calc); } REMINDER OF ARRAYS:

1. A A 65 #include int main() { char letterA = 'A'; char num = 65; printf("%c\n", letterA); printf("%c\n", num); printf("%d\n", letterA); } Output example #1: 2. A\0 A A A 4. A 65 A

#include int main() { char letterA = 'A'; char sentence[80] = "Welcome back!"; printf("%s\n", sentence); printf("%d\n", strlen(sentence)); printf("%s %c\n", sentence, letterA); } Output example #2: 2. Welcome back! 13 Welcome back! A 1. Welcome back! 14 Welcome back! A 3. “Welcome back!” 13 “Welcome back!” A 4. W 13 W

#include int main() { char sentence[] = "Welcome back!"; int i; for (i = 0; i < strlen(sentence); i+=2) { printf("%c ", sentence[i]); } printf("\n"); } Output example #3: 2. “Welcome back!” 1. Welcome back! 3. Gives you an error! 4. W l o e b c !

#include int main() { char sentence[80] = "Welcome back!"; sentence[3] = '\0'; printf("%s\n", sentence); printf("%d\n", strlen(sentence)); } Output example #4: 2. Welcome back! Wel 3 3. Welcome back! 3 4. Wel 13

#include int main() { char sentence[80] = "Welcome back!"; char sentence2[80] = "Hello class."; char sentence3[] = "Hello again."; strcpy(sentence2, sentence); printf("%s\n", sentence2); strcat(sentence, sentence3); printf("%s %s\n", sentence, sentence3); } Output example #5: 4. Welcome back! Welcome back!Hello again. Hello again. 2. Hello class. Welcome back!Hello again. 3. Hello class. Hello again. Hello again. 1. Welcome back! Welcome back!Hello again.

Strings are character arrays (example): #include int main() { char sentence[80]; /* large array length */ int i; sentence[0] = 'B'; sentence[1] = 'y'; sentence[2] = 'e'; sentence[3] = '\0'; printf("%s", sentence); /* prints Bye */ for (i = 0; i < strlen(sentence); i++) { printf("%c", sentence[i]); /* prints Bye */ } Some more string stuff: Caution when using scanf with strings: scanf(“%s”, string) /* no & is needed w/ %s*/ scanf(“%c”, &char) /* & is needed with %c */