Show Menu
Cheatography

ECE160 Exam 1 Cheat Sheet by

ECE160

Must-Know

int
-2,147­,48­3,648 to +1,147­,48­3,647
float
4bytes­,co­ntain 1 digit/­dec­imal, +-10^38, 7digit­spr­eci­sion,f, illega­lfl­oats: 6.2.2f­,6.-­3f,6.2
double
8bytes­,+-­10^­308­,14­dig­itp­recise
variable
upper/­low­ercase differ, reflects data stored, given to memory location
destru­ctive read
Reference
destru­ctive write
Write Over
types of c statements
declar­ati­ons­/ar­ith­metic instru­cti­ons­/co­ntrol instru­ctions
Order of Operations (L->R)
!, * / %, + -, < > <= =>, == !=, &&, ||, =
Functions
AND (&­&), OR (||), NOT (!)
QuadFo­rmula
(-b+sq­rt(­(b*­b)-­4ac­))/(2a)
While Loop
executed 0 or more times. Does test, then body
Do-While Loop
executed 1+ times. Does body, then test
absolute value
abs(#)

Formatting Printf

printf("%6d",123);
printf("%03d",5);
printf("%7.2f",6.789);
OUTPUTS WITHOUT SPACES
output: _ _ _ 1 2 3
output: 005
output: _ _ _ 6 . 7 9
 

Do While Loop (b)

i=5;
do
{
printf(i);
i++;
}
while(i>3);
Executed 1+ times. Output: 5

While Loop (b)

k=7;
while(k<5)
{
printf("%d", k);
k++;
}
Executed 0+ times. Output: (nothing)

Switch­-Case

int dc;
scanf(“%lf”, dc);
switch(dc) //can only switch a non double/non float 
{
	case 0 : printf (“switch case statement 1”);
	break;
	case 1 : printf(“switch case statement 2”);
	break;
	default; //do default case, below this line
	printf(“DEFAULT CASE”);
	break;
}

Logical If

If(logical expression)
{
	//block of code
}
else
{
	//statement if false
}
 

For Loop (a)

for(i=0;i<10;i++) //INIT, TEST, LOOP ALTER
{
printf("%d",i); //BODY
}
Rewrite of While Loop (a)

While Loop (a)

i=0; //INIT
while(i=0); //TEST
{
printf("%d",i); //BODY
i++; //LOOP ALTER
}
Rewrite of For Loop (a)

Pyramid Code Snippet

for(r=0;r<7;r++) //outer: 7 rows
{
for(s=0;s<r;s++) //controls spaces
{
printf(" ");
}
for(a=0;a<____*r;a++) //MATH 
{
printf("*"); //controls stars
}

Pyramid Math

r
# stars
0
11
1
9
1) Find m: m=(y2-­y1)­/(x­2-x1)
2) Find equation: b=y=mx
3) Use equation in blank in code
*y=ANSWER
   
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets