First Six Weeks Of Notes
First Six Weeks Of Notes ECE 173
Popular in Introduction to Computing
Popular in Electrical Engineering
This 14 page Bundle was uploaded by Evan Gjesvold on Sunday October 4, 2015. The Bundle belongs to ECE 173 at North Dakota State University taught by Na Gong in Fall 2015. Since its upload, it has received 98 views. For similar materials see Introduction to Computing in Electrical Engineering at North Dakota State University.
Reviews for First Six Weeks Of Notes
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 10/04/15
First Program include ltstdiohgt int main void printf programming is funn return 0 1 include ltstdiohgt gtshould be included at the beginning of your program gtthe contents of stdioh will be inserted where appears 2 int main void gtthis is the main function of the program gttells the computer this is the body of the program gtevery c program must have a main function a void this means that there is no argument for the function Leaving the space between the parentheses blank has the same function b int tells us the type of returning value In this case it is an integer Could have been a floating value a decimal number 3 and gt these include the content of the main function gt you need a main function for every program 4 printf programming is funn gttells the computer to print or display numbers or values gt the n tells the computer to begin a new line gt ex printf Good eveningn How are you will become gt Good evening How are you 4 Return 0 gt this means to finish execution of program and returns the system a 0 gt by default 0 means success Lecture 4 1 review a gtincude ltstdiohgt lt is important because it tells computer to insert predefined commands b int main void printf testingn1n2n3n return 0 int dictates the kind of return value In this case it is 0 an integer c we could insert system pause just before the return 0 command This would make the program pause and wait for a keyboard input to con nue 2 Comments 0 Used to document a program Increases readability and helps people understand the program they are looking at o It is ignored by the compiler 1 Line Comment a ll everything on this line is ignored because the II command dictates it so Everything following is ignored 2 Block comment a lasdfasasf Comment not read because between I and l asdfasdfasdf asdfl 3 Display the value of variables Example1 includeltstdiohgt int main void int sum sum 50 25 printf the value of sum is d and I am happy to get it sum gt instead of d we can also use i They have the same function example2 include ltstdiohgt int main void int num 1 num2 sum num1 50 num2 25 sum num1 num2 printf the value of sum of i and i is in num1 num2 sum Lecture 5 Chapter 4 Variables and Expressions 1 Variables a Used to store information Can be numbers or characters or other information such as addresses Can only be used after they have been declared ex num1 75 num250 sum num1 num2 Valid variable names must i begin with a letter or an underscore ii consist of letters digits or underscores only iii cannot be a c reserved word a word with a specified meaning ex int cannot be used because int is already defined as a integer Check page 426 for a list of reserved words iv be case sensitive uppercase vs lowercase is important ex Total total TOTAL Invalid variable names i does not begin with letter or underscore ii contains something other than letters digits and underscores iii if it is a c reserved word Variable name conventions i Conventions are standard practices not required by the program ii Normally variables are lowercase iii Constants are upper case ex pi is written as Pl iv Multiword underscores between words or unspaced with capitalization after first word ex mybirthday myBirthday Variable i is a memory location where a value can be stored ii Declaration 1 optional specifier datatype namelist 2 optional specifier can be signed or unsigned short or long 3 data type is the type of number int float double char 4 Numeric data types can be integer or float a floating float double long double b integer whole short int lin Type name Memory used Size Range short short int 2 bytes 3276832768 2147483648 2147483648 int 4 bytes 92233720368547 75808 long int 8 bytes float 4 bytes 10quot38 10quot38 double 8 bytes 10quot308 10quot308 double long 10 bytes 10quot4932 1OA4932 1 There are a variety of bases a decimal base 10 177 102 7101 710o b octal base 8 If the first digit of the integer value is a O the integer is taken as expressed in octal notation that is in base 80177 182 781 78 64 56 7 127 c hexadecimal base 16 0x177 1162 7161 716 256 1127375 Data type 1 Numeric data types a Whole Numbers Integers i shod ii int iii long b Real numbers floating point i float ii double iii long double 2 Character data 3 Boolean data 1 Bool can only store 0 and 1 How to assign values to variables 1 initial value assigning a variable during the declaration statement Ex int age 22Ex double rate 075 2 processing the assignment statement Ex lt this assigns a value to a variable Ex x y 5 3 get input from the user Ex scanf format addresslist i amp is to scanf as is to printf iL intage printf please input your age scanf d age b Review of printf i printf formatvariablelist ii int age 22 printf The number is in age iii int age 22 printf The number is on age iv int age 22 printf The number is xn age v float age 220 printf The number is fn age vi float age 220 printf The number is en age vii float age 220 printf The number is gn age viii char a a printf The letter is cn a ix Boo bool O printf The value is in bool 1 is multiplication 2 is division a division will generate the largest data type of the largest operand used in the operation b is the modulus operator lt divides and then displays only the remainder It will only generate a result of the same data type as the divisor 3 is subtraction 5 is addition Program looping I repetition 1 Review i scanf in ampnum this is how we display a user entered variable ii scanf i i i n ampnum1 ampnum2 ampnum3 b operations c additionn d subtraction e multiplication f division g modulus 2 Looping Repitition a example read two integers and print sum int num 1 num2 sum printf please input two integers n scanf i i ampnum1 ampnum2 sum num1 num2 ll perform additionz f printf i i i num1 num2 sum 3 Looping is when we perform a task repetitively 4 Done when you want to execute a block of code more than once a 3 types of code i while expression base block lexpression condition to be tested true or false repeats an operation repeatedly until the condition it is testing is false 999939 iI for couting loop iii dowhile similar to while always execute body at least once three differenct kinds of loops 1 while while expression base block 1 Relational Operators go in expression a ltessthan b ltess than or equal to c greater than d gt greater than or equal to e equal to f NOT equal to Loop body 2 int count int num1 num2 sum count 0 while count lt 5 scanf d d ampnum1 Next Statement ampnum2 sum num1 num2 printf d d d num1 num2 sum count count 1 iteration count count lt 5 loop body between 1 O T addition printf count 1 2 1 T addition print count 2 3 2 T addition print count 3 4 3 T addition print count 4 5 4 T addition print count 5 6 5 F Not performed because of condition 2 for another repetition structure uses special operators a assignment operator shortcut i aa5gta5 ii aa5gta5 iii aa5gta5 iv aal5gtal5 b increment decrement operators i aa1gta ii aa1gta iii x post increment 1 use the current value of this variable and then increase increment it iv x pre increment 1 increase increment the variable first and then use the new variable v x use the old variable first and then decreaseit vi x decrease the variable first and then use the new variable 3 dowhile LOOPING 1 use a while loop when there are conditions to be met a assignment operator shortcuts i aa1 ii a 1 b increment and decrement i x this means to use the variable first and then change it Try readying character by character if that helps ii x iii x this means to change the variable first and then use it for the operation Try reading character by character if that helps iv x 2 Using theforlooop a syntax i for initialization test incrementdecrementloop body ii Iteration condition counter 1 T counter 2 T counter 3 T counter 4 F 3 Using the do while loop a syntax i dooop body whilecondition condition is tested after the body of the loop is performed all Chapter 6 Making decisions in C Review scanf i ampage lt notice the lack of the new line character n scanf i i ampnum1 ampnum2 lt when asking for 2 items the separator in the scanf statement and the input must be the same Review of loops forinitiaization condition incrementdecrement body more body whie body more body do body more body whileconditionlt notice this is the only loop statement with a at the end Nested Loops inti1j1k3 fori1 iltk i f0ri 1 ilti i printfii printf n If and lfelse selection structure EDIEtin 33 E TinE El Engl Hegel slalemeni lt jri 1 if statement 2 if condition statement1 statement2 3 ifelse statement if condition statement statement else statement statement 4 Logical operatorcompound relationals ampamplogical AND RETURNS TRUE IF BOTH CONDITIONS ARE TRUE logical OR returns true if either of its conditions is true logical NOT reverses the truefalsity of its condition int input printf Pease input an integer for analysis if xgt0ampampxlt3 printf This is a number between 0 and threen int input printf Pease input an integer for analysis if xgt1xlt0 printf This number is greater than or equal to 1 or smaller than or equal to 0 int input printf Pease input an integer for analysis scanf i ampinput if xgt0ampampxlt3 printf This number isnt a number between 0 and 3n 4 Break and continue statemetns break statement terminates the Whole instruction for while dowhile continue statement stops the execution of current iteration and continues to the next iteration int i a b for i0 ilt5 i
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'