CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.

Slides:



Advertisements
Similar presentations
 #include  Using a directive to include a header file  Stdio.h = standard input output header file.
Advertisements

11-2 Identify the parts of the “main” function, which include Preprocessor Directives main function header main function body which includes Declaration.
Lecture 2 Introduction to C Programming
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
CS1061 C Programming Lecture 5: Building Blocks of Simple Programs A. O’Riordan, 2004.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Guide To UNIX Using Linux Third Edition
Basic Input/Output and Variables Ethan Cerami New York
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
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.
Introduction to C Language
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
CECS 121 EXAM 1. /* C Programming for the Absolute Beginner */ // by Michael Vine #include main() { printf(“\nC you later\n”); system(“pause”); }
C Programming Lecture 4 : Variables , Data Types
M. Taimoor Khan #include void main() { //This is my first C++ Program /* This program will display a string message on.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
/* C Programming for the Absolute Beginner */ // by Michael Vine #include main() { printf(“\nC you later\n”); system(“pause”); }
C++ Programming: Basic Elements of C++.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
CECS 130 EXAM 1. To declare a constant (read only) value: const int x = 20; const float PI = 3.14; Can we do this? const int x;
Khalid Rasheed Shaikh Computer Programming Theory 1.
/* C Programming for the Absolute Beginner */ // by Michael Vine #include main() { printf(“\nC you later\n”); system(“pause”); }
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Old Material escape sequences operator precedence printf() scanf() if() switch case &&,|| while, do-while, ++, -- functions New Material 1-D arrays string.
CECS 130 EXAM 1.  int main() { printf (“%c %c \n", 'a', 65); printf ("%d %ld\n", 1977, L); printf (" %10d \n", 1977); printf ("%010d \n", 1977);
Program Development Cycle 1.Edit program 2.Compile program - translates it from C to machine language 3. Run/execute your program. 4. If not satisfied,
CECS 121 Midterm Review Presented by REACH (If you have not signed the attendance sheet, please do so now!)
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Module 6 – Decision Control Statements Objectives  Understands Increment/Decrement operators, Conditional and special operators in C  Understands significance.
Lecture2.
Bill Tucker Austin Community College COSC 1315
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Computer Science 210 Computer Organization
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
EKT120 COMPUTER PROGRAMMING
EKT150 INTRODUCTION TO COMPUTER PROGRAMMING
Functions, Part 2 of 2 Topics Functions That Return a Value
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Week 4 – Repetition Structures / Loops
Getting Started with C.
2008/11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park
Formatted and Unformatted Input/Output Functions
Computer Science 210 Computer Organization
Functions, Part 2 of 3 Topics Functions That Return a Value
Program Breakdown, Variables, Types, Control Flow, and Input/Output
Lecture3.
C Programming Getting started Variables Basic C operators Conditionals
2. Second Step for Learning C++ Programming • Data Type • Char • Float
C++ Programming Basics
Programming Languages and Paradigms
DATA TYPES There are four basic data types associated with variables:
Introduction to C Programming
Functions, Part 2 of 3 Topics Functions That Return a Value
Functions, Part 2 of 3 Topics Functions That Return a Value
Getting Started With Coding
Presentation transcript:

CECS 121 Test 1

Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different functions. The main function is special because the values it returns are returned to the operating system Most main functions in this course do not take or pass information to the operating system

#include Using a directive to include a header file stdio.h = standard input output header file stdlib.h = ‘system’ commands Iostream.h= Input/Output stream header library Math.h= The Math library header file

 Definition: Escape sequences are specially sequenced characters used to format output  \” Ex: printf(“ \ “This is quoted text \ “ “)  \’ Ex: printf(“ \n A single quote looks like \’ \n”);  \* *\ Comment Block

To declare a constant (read only) value: const int x = 20 const float PI = 3.14 Can we do this? const int x;

TYPESIZEVALUES bool1 bytetrue (1) or false (0) char1 byte‘a’ to‘z’, ‘A’ to ‘Z’, ‘0’ to ‘9’, space, tab, and so on int4 bytes-2,147,483,648 to 2,147,483,647 short2 bytes-32,768 to 32,767 long4 bytes-2,147,483,648 to 2,147,483,647 float4 bytes+ - (1.2 x 10^-38 to 3.4 x 10^38) double8 bytes+- (2.3 x 10^-308 to -1.7 x 10^308)

X++; Tells the function to use the current value of x and increment it by 1. ++x; Increment the value of x by 1 and use the new value for calculations. x--; Tells the function to use the current value of x and decrease its value by 1. --x; Decrease the value of x by 1 and use the new value for calculations. Int x=0; printf(“The Value of x is: %d”, x++); printf(“\n The Value of x is: %d”,++x); Would results in: The Value of x is: 0 The Value of x is: 2

Variables and Constants To declare a constant (read only) value: const int x = 20 const float PI = 3.14 What is wrong with this code?

Variables and Constants Are the following valid names for a variables in C: 1) _name 1) $student_number 1) #salary 1) 9pins+1 and 1) First-name 1) TheIncrediblyEdiblySpiderManWithTheVeryLongNameOfMoreTha n50Characters

#include int main() { int x; for ( x = 0; x < 10; x++ ){ printf( "%d\n", x ); } getchar(); }

 Can you explain what the code is doing?

 Syntax: scanf(“conversion specifier”, variable);

Do you know the answers to these?  A. !( 1 || 0 )  B. !( 1 || 1 && 0 )  C. !( ( 1 || 0 ) && 0 )

 A. !( 1 || 0 ) ANSWER: 0  B. !( 1 || 1 && 0 ) ANSWER: 0 (AND is evaluated before OR)  C. !( ( 1 || 0 ) && 0 ) ANSWER: 1 (Parenthesis are useful)

Syntax:

Else if:

 Can you write code that will ask a user to enter a number 1, 2, or 3 and print out the following:

 while ( condition ) { Code to execute while the condition is true }  Quiz: Can you write a program that prints x while x increments from 0 to 10?

 do { } while ( condition );  What is the main difference between “Do while” and “while”?

 while ( condition ) { Code to execute while the condition is true }  do { } while ( condition );  Do{} while() executes code at least once!

 Write a program using a WHILE Loop to display all of the multiples of 5 from 0 to 100.

#include int main() { int x=0; while (x<100) { printf( "%d\n", x*5 ); x++; } getchar(); }

 Use when the number of iterations is already known  Syntax: for ( variable initialization; condition; variable increment/decrement) { Code to execute while the condition is true }

#include int main() { int x; for ( x = 0; x < 10; x++ ){ printf( "%d\n", x ); } getchar(); }

 Write a program using a FOR Loop to display all of the multiples of 5 from 0 to 100.

#include int main() { int x; for ( x = 0; x < =20; x++ ) { printf( "%d\n", x*5 ); } getchar(); }

x++; x--; Postfix ++x; --x; Prefix main() {int x = 0; int y = 0; printf(“\n The value of y is %d \n”, y++); printf(“\n The value of x is %d \n”, ++x); } Answer: 0 1

 Use to manipulate flow in loops  What does a Break statement do when executed within a loop?  What does a Continue statement do when executed within a loop?

#include main() { int x; for ( x = 10; x >5; x-- ) { if (x==7) break; } printf( “\n %d \n ”, x ); } #include main() { int x; for ( x = 10; x >5; x-- ) { if (x==7) continue; printf( “\n %d \n ”, x ); }