Binary multiplication

Slides:



Advertisements
Similar presentations
printf() Documentation info:
Advertisements

Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
Dale Roberts Basic I/O – printf() CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
Display a 12-Month Calendar CS-2301 D-term Programming Assignment #2 12-Month Calendar CS-2301 System Programming C-term 2009 (Slides include materials.
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
C Formatted Input/Output /* Using Integer Conversion Specifiers */ #include int main ( ) { printf( "%d\n", 455 ); printf( "%i\n", 455 ); printf( "%d\n",
Computer Science 210 Computer Organization Floating Point Representation.
Printing. printf: formatted printing So far we have just been copying stuff from standard-in, files, pipes, etc to the screen or another file. Say I have.
C PROGRAMMING LECTURE 17 th August IIT Kanpur C Course, Programming club, Fall by Deepak Majeti M-Tech CSE
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Simple Data Type Representation and conversion of numbers
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
Chapter 9 Formatted Input/Output Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
 Pearson Education, Inc. All rights reserved Formatted Output.
EPSII 59:006 Spring Introduction In this lecture  Formatted Input/Output scanf and printf  Streams (input and output) gets, puts, getchar, putchar.
 2005 Pearson Education, Inc. All rights reserved Formatted Output.
Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
ACM notes Can work on the problems anytime throughout the term Contest conflict -- The GRE subject test is Nov. 10th! int x; while (cin >> x) { cout
Sales person receive RM200/week plus 9% of their gross sales for that week. Write an algorithms to calculate the sales person’s earning from the input.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
C++ Programming, Namiq Sultan1 Chapter 3 Expressions and Interactivity Namiq Sultan University of Duhok Department of Electrical and Computer Engineerin.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
Standard I/O Functions – printf() Without specifying any display formatting, the printf() function will use DEFAULT setting: Print in a field of minimum.
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
Introduction to Computer Organization & Systems Topics: Types in C: floating point COMP C Part III.
C How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
CS 1704 Introduction to Data Structures and Software Engineering.
ACM notes Sometimes a problem is much more difficult than expected! Basic approach:
28 Formatted Output.
Chapter 9 - Formatted Input/Output
C Formatted Input/Output
CSE 220 – C Programming Bitwise Operators.
Formatted Input and Output
Code -> Build -> Run
Chapter 9 C Formatted Input/Output
ECE Application Programming
Design Patterns (cont.) and Coding
TMF1414 Introduction to Programming
Introduction to C CSE 2031 Fall /3/ :33 AM.
What to bring: iCard, pens/pencils (They provide the scratch paper)
Input and Output Lecture 4.
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
Chapter 08- printf and scanf
Formatting Output.
توابع ورودي-خروجي.
Lecture 13 Input/Output Files.
Manipulators CSCE 121 J. Michael Moore
A First Book of ANSI C Fourth Edition
Chapter 9 - Formatted Input/Output
Differences between Java and C
Chapter 4 Managing Input and Output Operations
Conversion Check your class notes and given examples at class.
Introduction to Java Applications
Robust Coding and Debugging
Robust Coding and Debugging
Introduction to C CSE 2031 Fall /15/2019 8:26 AM.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
ECE 120 Midterm 1 HKN Review Session.
Presentation transcript:

Binary multiplication #define Sj (strlen(B)-j-1) #define Si (strlen(A)-i-1) int main() { int i, T[1000]; char A[300], B[300]; while (cin >> A >> B) { for (i=0 ; i<1000 ; ++i) T[i] = 0; for (i=0 ; A[i] != 0 ; ++i) if (A[Si] == '1') for (int j=0 ; B[j] != 0 ; ++j) if (B[Sj] == '1') ++T[999-i-j]; /* add columns */ /* then simplify and print */ } } 1001110 times 11001 create a table 0000000000001001110 0000000000000000000 0000000001001110000 0000000010011100000 0000000011013211110 add the columns 0000000011110011110 simplify STL: http://www.sgi.com/Technology/STL

when you see this, catch up with any pending operations Fraction calculator getNum(…) getOp(…) operate(n1,d1,n2,d2,op) simplify(int& n,int& d) gets a number or returns an error functions to help parse... gets an operator or returns an error does the arithmetic reduces n/d to lowest terms 18 - --5 / 7 * 3 + 1 - 3 ... evaluate as you go getNum(…) when you see this, catch up with any pending operations getOp(…) 18 - 15/7 pending immediate 111/7 + pending

allowed size modifiers C Output printf, fprintf, sprintf(char* s, const char* format, …) the destination the format string the values possible format strings % -#0 12 .4 h d d decimal integers u unsigned (decimal) ints o octal integers x hexadecimal integers f doubles (floats are cast) e doubles (exp. notation) g f or e, if exp < -3 or -4 c character s string n outputs # of chars written !! % two of these print a ‘%’ minimum field width size modifier type precision allowed size modifiers flags - left-justify 0 pad w/ zeros + use sign (+ or -) (space) use sign ( or -) # deviant operation h short l long (lowercase L) L long double start character

C Output value = 42 value = -42 %10.4d 0042 -0042 %-#12x 0x2a 0xffffffd6 value = 42 value = -42.419 %+10.4g +42 -42.42 %- 10.4g 42 -42.42 %-#10.4g 42.00 -42.42 value = “forty-two” %10.5s forty

Stuff I’d never heard of... sprintf(s,”%*.*f”,width,prec,number) if width = 10, prec = 4, and number = 3.14159, then s == “ 3.142” What if you want to know how much was written to s ? sprintf(s,”%*.*f %n”,width,prec,number,&n) after which n == 11

Bugs & No Bugs class Line { Point* p1; Point* p2; #include <stdio.h> char *T="IeJKLMaYQCE]jbZRskc[SldU^V\\X\\|/_<[<:90!\"$434-./2>]s", K[3][1000],*F,x,A,*M[2],*J,r[4],*g,N,Y,*Q,W,*k,q,D;X(){r [r [r[3]=M[1-(x&1)][*r=W,1],2]=*Q+2,1]=x+1+Y,*g++=((((x& 7) -1)>>1)-1)?*r:r[x>>3],(++x<*r)&&X();}E(){A||X(x=0,g =J ),x=7&(*T>>A*3),J[(x[F]-W-x)^A*7]=Q[x&3]^A*(*M)[2 +( x&1)],g=J+((x[k]-W)^A*7)-A,g[1]=(*M)[*g=M[T+=A ,1 ][x&1],x&1],(A^=1)&&(E(),J+=W);}l(){E(--q&&l () );}B(){*J&&B((D=*J,Q[2]<D&&D<k[1]&&(*g++=1 ), !(D-W&&D-9&&D-10&&D-13)&&(!*r&&(*g++=0) ,* r=1)||64<D&&D<91&&(*r=0,*g++=D-63)||D >= 97&&D<123&&(*r=0,*g++=D-95)||!(D-k[ 3] )&&(*r=0,*g++=12)||D>k[3]&&D<=k[ 1] -1&&(*r=0,*g++=D-47),J++));}j( ){ putchar(A);}b(){(j(A=(*K)[D* W+ r[2]*Y+x]),++x<Y)&&b();}t () {(j((b(D=q[g],x=0),A=W) ), ++q<(*(r+1)<Y?*(r+1): Y) )&&t();}R(){(A=(t( q= 0),'\n'),j(),++r [2 ]<N)&&R();}O() {( j((r[2]=0,R( )) ),r[1]-=q) && O(g-=-q) ;} C(){( J= gets (K [1]))&&C((B(g=K[2]),*r=!(!*r&&(*g++=0)),(*r)[r]=g-K[2],g=K[2 ],r[ 1]&& O()) );;} main (){C ((l( (J=( A=0) [K], A[M] =(F= (k=( M[!A ]=(Q =T+( q=(Y =(W= 32)- (N=4 )))) +N)+ 2)+7 )+7) ),Y= N<<( *r=! -A)) class Line { Point* p1; Point* p2; Line(Point* p1, Point* p2) p1 = new Point(); p2 = new Point(); this.p1 = p1; this.p2 = p2; } // other methods 2000 IOCCC winner “Best use of flags” www.cs.hmc.edu/~dodds/anderson.c

“Power Towers” 20000 3 Input: n b Idea: 20000 3 Input: n b Idea: Write n in base b -- including all exponents! 9 5 3 2 20000 == 3 + 3 + 2*3 + 2*3 + 2 Output: 2 3 3+2 3 2 20000 = 3 +3 +2*3 +2*3 +2