12
Summary

Summary

Embed Size (px)

DESCRIPTION

Summary. Data Types. int A; I am declaring a variable A, which is an integer. Arrays. int A[50]; I am declaring an array A. This array has 50 elements , and each element is an integer . A[0] is the first element of the array A[49] is the last element of the array. - PowerPoint PPT Presentation

Citation preview

Page 1: Summary

Summary

Page 2: Summary

Data Types

int A;

I am declaring a variable A, which is an integer.

Page 3: Summary

Arrays

int A[50];

I am declaring an array A. This array has 50 elements, and each element is an integer.

A[0] is the first element of the arrayA[49] is the last element of the array

Page 4: Summary

if, else if, elseif ( statement){

your code here}else if ( statement){

your code here}else if (statement){

your code here}…else{

your code here}

Page 5: Summary

while

while(statement){

your code here}

Page 6: Summary

for

for(initial condition ; statement ; final operation){

your code here}

Page 7: Summary

function

int foo(int A, int B){

int C;your code herereturn C;

}

Page 8: Summary

How to call your function

void main(){

int X;int Y;int Z;Z = foo (X, Y);printf(foo(%d, %d) = %d\n, X, Y, Z);

}

Page 9: Summary

Struct

typedef struct tag_name{

type element1; type element2;

} tag_name;

Page 10: Summary

Struct Example#include <stdio.h>

typedef struct Student{

int midterm;//%40int hw;//%20int final;//%40int average;

} Student;

void main(){

Student Veli;Veli.hw = 80;Veli.midterm = 90;Veli.final = 100;Veli.average = (Veli.hw*20 + Veli.midterm*40 + Veli.final*40)/100;printf("Veli has an average grade of %d \n", Veli.average);

}

Page 11: Summary

Base Arithmetic

• Binary numbers (base 2): Use only digits 0 and 1

• Decimal numbers (base 10): Use digits 0,1,2,3,4,5,6,7,8,9

• Hexadecimal numbers (bas 16): Use digits 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F– A = 10, B = 11, C = 12, D = 13, E = 14, F = 15

Page 12: Summary

One’s and Two’s complement

• 1’s complemenf of an N-bit number: Invert all the bits in binary representation.

• 2’s complement of an N-bit number: subtract the number from 2N.