8 views

Uploaded by Shohagh Shosagh

C programming lecture

- Letter of Motivation - Erasmus
- Example Solusion
- AT&T supports SUNY Oswego Student Computer Science
- ejemplo dos fases.pdf
- Program Comp Science
- lattice structure for FIR filter
- Q Learning Ejemplo
- F.K. Miyazawa and Y.Wakabayashi- Three-dimensional packings with rotations
- 05 Machine Learning lecture
- Immadi Pulikeshi
- Brute Force Search
- Fir Filter Design
- Tutorial 5 Chapter OS Deadlockver2
- DS 2 marks
- CH1
- IIT Kanpur
- Game Theory
- $R83N7A4
- A Sample Copy of Thesis
- prim algo

You are on page 1of 9

GCD Using Euclids method (m n > 0): GCD(m, n) = n, if m%n = 0 GCD(n, m%n), otherwise

Dijkstras method (assuming m > n > 0) GCD(m, n) is same as GCD(m n, n): n, if m = n GCD(m, n) = GCD(m n, n), if m > n GCD(m, n m), if n > m

R. K. Ghosh (IIT-Kanpur) C Programming March 2, 2011 7/8

GCD: Euclids Method

#i n c l u d e < s t d i o . h> i n t GCD( i n t m, i n t n ) { i f ( (m % n ) == 0 ) return n ; r e t u r n GCD( n , m % n ) ; } i n t main ( ) { i n t m, n ; p r i n t f ( E n t e r m, n ) ; s c a n f ( %d %d , &m, &n ) ; i f (m < n ) p r i n t f ( GCD(%d , %d ) = %d\n , m, n , GCD( n , m) ) ; else p r i n t f ( GCD(%d , %d ) = %d\n , m, n , GCD(m, n ) ) ; }

R. K. Ghosh (IIT-Kanpur) C Programming March 2, 2011 7/8

GCD: Dijkstra Method

#i n c l u d e < s t d i o . h> i n t GCD( i n t m, i n t n ) { i f (m == n ) r e t u r n m; i f (m > n ) r e t u r n GCD(m , n ) ; n r e t u r n GCD(m, nm) ; } i n t main ( ) { i n t m, n ; p r i n t f ( E n t e r m and n : ) ; s c a n f ( %d %d , &m, &n ) ; p r i n t f ( GCD(%d , %d ) = %d\n , m, n , GCD(m, n ) ) ; }

R. K. Ghosh (IIT-Kanpur)

C Programming

March 2, 2011

7/8

Binomial Coecient 1, if r = 0 = 1, if n = r n1 r + n1 otherwise r1

n r

R. K. Ghosh (IIT-Kanpur)

C Programming

March 2, 2011

7/8

Binomial Coecient

#i n c l u d e < s t d i o . h> i n t binom ( i n t n , i n t r ) { i f ( r == 0 | | n == r ) return 1; r e t u r n binom ( n 1 , r ) + binom ( n 1 , r 1); } i n t main ( ) { int n , r ; p r i n t f ( Enter n , r : ) ; s c a n f ( %d %d , &n , &r ) ; p r i n t f ( binom(%d , %d ) = %d\n , n , r , binom ( n , r ) ) ; }

R. K. Ghosh (IIT-Kanpur)

C Programming

March 2, 2011

7/8

Pascals Triangle

i n t main ( ) { int i , j , n; p r i n t f ( Enter n : ) ; s c a n f ( %d , &n ) ; f o r ( i = 0 ; i < n ; i ++) { f o r ( j = 0 ; j <= i ; j ++) { p r i n t f ( %6d , binom ( i , j ) ) ; } p r i n t f ( \n ) ; } }

R. K. Ghosh (IIT-Kanpur)

C Programming

March 2, 2011

7/8

Tower of Hanoi

2

B C

Base case is moving the disk with largest diameter. So, spec of tower(n, A, B, C):

If n = 1 then move disk n from A to C Else execute following steps:

1 2

B 3

R. K. Ghosh (IIT-Kanpur)

C Programming

March 2, 2011

7/8

Tower of Hanoi

#i n c l u d e < s t d i o . h> v o i d t o w e r ( i n t n , c h a r A , c h a r B , c h a r C) { i f ( n == 1 ) { p r i n t f ( Move d i s k 1 from %c t o %c \n , A , C ) ; return ; } t o w e r ( n 1 , A , C , B ) ; p r i n t f ( Move d i s k %d from %c t o %c \n , n , A , C ) ; t o w e r ( n 1 , B , A , C ) ; return ; } i n t main ( ) { int n; p r i n t f ( Enter n : ) ; s c a n f ( %d , &n ) ; t o w e r ( n , A , B , C ) ; }

R. K. Ghosh (IIT-Kanpur)

C Programming

March 2, 2011

7/8

Merge Sort

Merging

auxiliary array (double the size of A or B) smaller 0 1 smaller 2 3 smaller smaller comp 0 3 4 6 8 11 12 13 A 1 2 5 7 9 10 14 15 B 0 3 4 6 8 11 12 13 A comp 1 2 5 7 9 10 14 15 B 0 comp 3 4 6 8 11 12 13 A 1 2 5 7 9 10 14 15 B

March 2, 2011 8/8

comp 0 3 4 6 8 11 12 13 A 1 2 5 7 9 10 14 15 B

R. K. Ghosh (IIT-Kanpur)

C Programming

- Letter of Motivation - ErasmusUploaded byLavinia Năstase
- Example SolusionUploaded byAshish Patel
- AT&T supports SUNY Oswego Student Computer ScienceUploaded byEllen Webner
- ejemplo dos fases.pdfUploaded byTato Flores
- Program Comp ScienceUploaded byToni D.
- lattice structure for FIR filterUploaded byjaishpanjwani
- Q Learning EjemploUploaded byFabián Sanchez
- F.K. Miyazawa and Y.Wakabayashi- Three-dimensional packings with rotationsUploaded byMnaom
- 05 Machine Learning lectureUploaded byrighthearted
- Immadi PulikeshiUploaded byMallikarjun Mbr
- Brute Force SearchUploaded byrox_369
- Fir Filter DesignUploaded byarjun cat
- Tutorial 5 Chapter OS Deadlockver2Uploaded byokashii_kioku
- DS 2 marksUploaded bySaravanan Sar
- CH1Uploaded byAnonymous GsPflButzp
- IIT KanpurUploaded bydeepak
- Game TheoryUploaded bydipnis
- $R83N7A4Uploaded byneilwu
- A Sample Copy of ThesisUploaded byFeraydoon Nasratzada
- prim algoUploaded byAhmad Nazri Bin Zainal
- 05591234Uploaded bySabahat Kanwal
- 2D Array.docxUploaded bySyed Jibran Ali Bukhari
- lect04Uploaded bymohamed
- Erased_PDF 31.pdfUploaded byChad Mcdonald
- Adapt Filt LibUploaded byJuank Palomos
- scimakelatex.25656.frank+millerUploaded bymaxxflyy
- UntitledUploaded byRajeshKanna Rajendran
- Natural Language Processing (Synopsis)Uploaded bysanjaykumarguptaa
- STLFUploaded byShubham Ghore
- Dw 34752755Uploaded byAnonymous 7VPPkWS8O

- Java TutorialsUploaded byPiero Amauche
- LectureUploaded byShohagh Shosagh
- Understanding JavaUploaded byShohagh Shosagh
- c programmingUploaded byShohagh Shosagh
- C ProgrammingUploaded byShohagh Shosagh
- Lecture about cUploaded byShohagh Shosagh
- lecture about c programmingUploaded byShohagh Shosagh
- lect14Uploaded byShohagh Shosagh
- lect15Uploaded byShohagh Shosagh

- Manager as a Person 1Uploaded bySiddharthh Nutan Gokani
- spruh73c.pdfUploaded byFaizan Khan
- FACSUploaded byKarthick Thiyagarajan
- Epythermal Arribas 1995 MinAssocCanada23Uploaded byHerman_ML
- BF029943 Specification BTEC Level 1 2 First Award Principles of Applied ScienceUploaded bySam Turner
- S0_FrontMatter[1].pdfUploaded byrq3745
- Allinone Telesystem User Manual RCU Universal Rev06Uploaded byAnonymous glUUSlNp
- Terrain Referenced Navigation of AUVs and Submarines Using Multibeam Echo SoundersUploaded byTony Thomas
- Money_Love.pdfUploaded byJohn
- FRP Composite reinforcedUploaded byNilesh Kitey
- companyoverview-sept2016Uploaded byJYM2015
- The semiotic gesture Ole KühlUploaded byEscuela De Arte
- Physics Lab 01: Balloons and Static ElectricityUploaded byHamza Qureshi
- welcome newsletter 4 16Uploaded byapi-269237246
- ESTIMATION METHOD OF SHIP MAIN PROPULSION POWER, ONBOARD POWER STATION ELECTRIC POWER AND BOILERS CAPACITY BY MEANS OF STATISTICS , 003.pdfUploaded bycupidkhh
- AWS90 Structural Nonlin Ch03 ContactUploaded byRaki Rock
- 3. Hookes LawUploaded byDebora Tresia Purba
- Sample Exam 1 - Modules 1-4Uploaded byPhilip Walker
- (INTERNAL) EMD Generator User Guide TRP3871Uploaded byAbdullah AlHashimi
- Rsh Qam11 Ch03 GEUploaded bybilal
- Foci and Bases for Employee CommitmentUploaded bymanique_abeyrat2469
- Lexus_GS300_GS430_service_manual 9Uploaded byseregap84
- Chapter 3 Step Wise an Approach to Planning Software Projects 976242065Uploaded byRiajimin
- 03-03-14 Functionality BRAUMAT ClassicUploaded byDo Van Tu
- Www.ignou.ac.in Upload Unit 4Uploaded byKushagra Dwivedi
- Fireworks Making 101Uploaded byhtmagic
- 1-Book Reviews. Slavoj Z Izek, A Critical IntroductionUploaded byktabxan
- Cambio Rapido Qc GimaticUploaded byHIDRAFLUID
- Fiesta Gas GrillUploaded byfogdart
- ACT With LoveUploaded byCris Frasineanu