SlideShare a Scribd company logo
Solutions to Creative
Problems
Lecture 16
Feb 12, 2008
Creative Question
• Given a Black box that takes as input
two symmetric matrices and outputs the
product of the same, use the black box
to multiple two arbitrary matrices.
a b
x
c d
0 0 a b
0 0 c d
a c 0 0
b d 0 0

e g
f h

x

=

p q
r s

0 0 e f
0 0 g h
e g 0 0
f h 0 0

p
r
0
0

q
s
0
0

0 0
0 0
u v
wx
Creative Question
• Given a Black box that takes as input a
matrix and outputs the square of the
same, use the black box to multiple two
arbitrary matrices.
a b
x
c d
0 0 a b
0 0 c d
e g 0 0
f h 0 0

e g
f h

x

=

p q
r s

0 0 a b
0 0 c d
e g 0 0
f h 0 0

p
r
0
0

q
s
0
0

0 0
0 0
u v
wx
Creative Question
• Given a Black box that takes as input a
lower triangular matrix and an upper
triangular matrix and outputs the
product of the same, use the black box
to multiple two arbitrary square
matrices.
a b
x
c d
0 0 0 0
0 0 0 0
a b 0 0
c d 0 0

e g
f h

x

=

p q
r s

0 0 e g
0 0 f h
0 0 0 0
0 0 0 0

0
0
0
0

0
0
0
0

0
0
p
r

0
0
q
s
Creative Question
• Given a Black box that takes as input
two lower triangular matrices and
outputs the product of the same, use
the black box to multiple two arbitrary
square matrices.
a b
x
c d
000000
000000
000000
000000
00ab00
00cd00

x

e g
f h

=

000000
000000
eg0000
f h0000
000000
000000

p q
r s

=

000000
000000
000000
000000
pq0000
r s0000
Functions = outsourcing
• Break large computing tasks into small ones
• Helps you to build on what others have done
• You and others write functions
• When you want to build a program, find out how to use
the function and use it.

• Use standard functions provided by the
library.
• You are hidden from the implementation
• Example – you don’t have to worry about how pow(m,n)
is implemented

• As engineers from different disciplines you
will use and develop different set of functions
Modular Programming
Subprograms
functions in C, C++, procedures and functions in
Pascal
facilitate modular programming
Overall task is divided into modules
Each module - a collection of subprograms

a subprogram may be invoked at several points
A commonly used computation

hiding the implementation
incorporating changes
easier
Example of function sets
• String manipulation
• Mathematical
• Finite Element Method
• Used in structural analysis by Mechanical, Civil, Aero,
etc. for stress calculations etc.

• Most function libraries cost a lot
• Business opportunity – identify functions that are useful
to you area of study, create libraries.

• Functions for use in different software.
• Say, functions for web services
Basics
• Function is a part of your program.
• It cannot be a part of any other function
• Main() is a function: it is the main function. Execution starts
there or the control flow starts there
• From there it can flow from one function to another, return after
a computation with some values, probably, and then flow on.

• Transfer of control is affected by calling a function
•
•
•
•
•
•
•

With a function call, we pass some parameters
These parameters are used within the function
A value is computed
The value is returned to the function which initiated the call
The calling function can ignore the value returned
It could use it in some other computation
A function could call itself, these are called recursive function
calls
Add function to your Program
• A program was a set of variables, and
assignments to variables
• Now add function to it.
•
•
•
•

Set of variables
Some functions including main()
Communicating values to each other
Computing and returning values for each other

• Instead of one long program, we now write
structured program composed of functions
Features
• C program -- a collection of functions
– function main ( ) - mandatory - program starts here.
• C is not a block structured language
– a function can not be defined inside another function
– only variables can be defined in functions / blocks
• Variables can be defined outside of all functions
– global variables - accessible to all functions
– a means of sharing data between functions - caution
• Recursion is possible
– a function can call itself - directly or indirectly
Function template
Return-type function-name(argument
declarations)
{
declaration and statements
return expression;
}
Function Definition in C
return-type function-name (argument declarations)
{
variable/constant declarations and
No function
statements }
declarations here!
Arguments or parameters:
the means of giving input to the function
type and name of arguments are declared

names are formal - local to the function
Return Value: for giving the output value
return ( expression ); -- optional
Invoking a function: funct-name(exp1,exp2,…,expn)

Matching the
number and type
of arguments
Function Prototype
• defines
– the number of parameters, type of each
parameter,
– type of the return value of a function

• used by the compiler to check the usage
– prevents execution-time errors

• function prototype of power function
– int power ( int, int );
– no need for naming the parameters

• function prototypes - given in the beginning
Power Function
#include <stdio.h>
function prototype
int power (int, int);
-- Computes the nth
power of base.
main () {
for ( int i = 0; i < 20; i ++ )
printf(“%d %d %dn”, i, power(3,i), power(-4,i);}
int power (int base, int n) {
int i, p = 1;
for ( i = 1; i <= n ; i ++)
p = p ∗ base;
return p;
}

A block

Invocation with
arguments
Calling Power Function with i=3
printf(“%d %d %dn”, i, power(3,i), power(-4,i);}

27
int power (int base, int n) {
int i, p = 1;
for ( i = 1; i <= n ; i ++)
p = p ∗ base;
return p;
}

-64

int power (int base, int n) {
int i, p = 1;
for ( i = 1; i <= n ; i ++)
p = p ∗ base;
return p;
}
Thank You
• For Exam
– Bring BOTH your Institute ID card and RFID card - else you shall not be permitted to
write the exam.

• All the Best

More Related Content

What's hot

Python advanced 1.handle error, generator, decorator and decriptor
Python advanced 1.handle error, generator, decorator and decriptor Python advanced 1.handle error, generator, decorator and decriptor
Python advanced 1.handle error, generator, decorator and decriptor John(Qiang) Zhang
 
Functional programming 101
Functional programming 101Functional programming 101
Functional programming 101
Maneesh Chaturvedi
 
Talk on Standard Template Library
Talk on Standard Template LibraryTalk on Standard Template Library
Talk on Standard Template Library
Anirudh Raja
 
Fda unit 1 lec 1
Fda unit 1 lec  1Fda unit 1 lec  1
Fda unit 1 lec 1
Eugin Britto
 
C++ Function
C++ FunctionC++ Function
C++ FunctionHajar
 
Python Generators
Python GeneratorsPython Generators
Python Generators
Akshar Raaj
 
Functional programming java
Functional programming javaFunctional programming java
Functional programming java
Maneesh Chaturvedi
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
kavitha muneeshwaran
 
Iterarators and generators in python
Iterarators and generators in pythonIterarators and generators in python
Iterarators and generators in python
Sarfaraz Ghanta
 
Function overloading
Function overloadingFunction overloading
Function overloading
Sudeshna Biswas
 
Reference Parameter, Passing object by reference, constant parameter & Defaul...
Reference Parameter, Passing object by reference, constant parameter & Defaul...Reference Parameter, Passing object by reference, constant parameter & Defaul...
Reference Parameter, Passing object by reference, constant parameter & Defaul...
Meghaj Mallick
 
Functions
FunctionsFunctions
Lecture 4
Lecture 4Lecture 4
Lecture 4
Mohammed Saleh
 
Ankita sharma focp
Ankita sharma focpAnkita sharma focp
Ankita sharma focp
AnkitaSharma463389
 
C++ functions
C++ functionsC++ functions
C++ functions
Dawood Jutt
 
Function Pointer in C
Function Pointer in CFunction Pointer in C
Function Pointer in C
Lakshmi Sarvani Videla
 
Functions
FunctionsFunctions
Functions
PralhadKhanal1
 

What's hot (19)

Python advanced 1.handle error, generator, decorator and decriptor
Python advanced 1.handle error, generator, decorator and decriptor Python advanced 1.handle error, generator, decorator and decriptor
Python advanced 1.handle error, generator, decorator and decriptor
 
Functional programming 101
Functional programming 101Functional programming 101
Functional programming 101
 
Talk on Standard Template Library
Talk on Standard Template LibraryTalk on Standard Template Library
Talk on Standard Template Library
 
Fda unit 1 lec 1
Fda unit 1 lec  1Fda unit 1 lec  1
Fda unit 1 lec 1
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
Python Generators
Python GeneratorsPython Generators
Python Generators
 
Functional programming java
Functional programming javaFunctional programming java
Functional programming java
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
 
Iterarators and generators in python
Iterarators and generators in pythonIterarators and generators in python
Iterarators and generators in python
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Team 6
Team 6Team 6
Team 6
 
Reference Parameter, Passing object by reference, constant parameter & Defaul...
Reference Parameter, Passing object by reference, constant parameter & Defaul...Reference Parameter, Passing object by reference, constant parameter & Defaul...
Reference Parameter, Passing object by reference, constant parameter & Defaul...
 
Functions
FunctionsFunctions
Functions
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Ankita sharma focp
Ankita sharma focpAnkita sharma focp
Ankita sharma focp
 
C++ functions
C++ functionsC++ functions
C++ functions
 
Function Pointer in C
Function Pointer in CFunction Pointer in C
Function Pointer in C
 
Functions
FunctionsFunctions
Functions
 

Viewers also liked

Lec10-CS110 Computational Engineering
Lec10-CS110 Computational EngineeringLec10-CS110 Computational Engineering
Lec10-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec21-CS110 Computational Engineering
Lec21-CS110 Computational EngineeringLec21-CS110 Computational Engineering
Lec21-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec19-CS110 Computational Engineering
Lec19-CS110 Computational EngineeringLec19-CS110 Computational Engineering
Lec19-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec12-CS110 Computational Engineering
Lec12-CS110 Computational EngineeringLec12-CS110 Computational Engineering
Lec12-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec15-CS110 Computational Engineering
Lec15-CS110 Computational EngineeringLec15-CS110 Computational Engineering
Lec15-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec14-CS110 Computational Engineering
Lec14-CS110 Computational EngineeringLec14-CS110 Computational Engineering
Lec14-CS110 Computational Engineering
Sri Harsha Pamu
 

Viewers also liked (7)

Lec10-CS110 Computational Engineering
Lec10-CS110 Computational EngineeringLec10-CS110 Computational Engineering
Lec10-CS110 Computational Engineering
 
Lec21-CS110 Computational Engineering
Lec21-CS110 Computational EngineeringLec21-CS110 Computational Engineering
Lec21-CS110 Computational Engineering
 
Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
 
Lec19-CS110 Computational Engineering
Lec19-CS110 Computational EngineeringLec19-CS110 Computational Engineering
Lec19-CS110 Computational Engineering
 
Lec12-CS110 Computational Engineering
Lec12-CS110 Computational EngineeringLec12-CS110 Computational Engineering
Lec12-CS110 Computational Engineering
 
Lec15-CS110 Computational Engineering
Lec15-CS110 Computational EngineeringLec15-CS110 Computational Engineering
Lec15-CS110 Computational Engineering
 
Lec14-CS110 Computational Engineering
Lec14-CS110 Computational EngineeringLec14-CS110 Computational Engineering
Lec14-CS110 Computational Engineering
 

Similar to Lec16-CS110 Computational Engineering

Functions
FunctionsFunctions
Funtions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the topsFuntions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the tops
sameermhr345
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
LPU
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
Anil Pokhrel
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
sangeeta borde
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
Ashim Lamichhane
 
Functions_new.pptx
Functions_new.pptxFunctions_new.pptx
Functions_new.pptx
Yagna15
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
GebruGetachew2
 
c++ UNIT II.pptx
c++ UNIT II.pptxc++ UNIT II.pptx
Functions in c
Functions in cFunctions in c
Functions in c
sunila tharagaturi
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
VAIBHAVKADAGANCHI
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
imtiazalijoono
 
08 subprograms
08 subprograms08 subprograms
08 subprograms
baran19901990
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
Bharath904863
 
Python_Functions_Unit1.pptx
Python_Functions_Unit1.pptxPython_Functions_Unit1.pptx
Python_Functions_Unit1.pptx
Koteswari Kasireddy
 
Function (rule in programming)
Function (rule in programming)Function (rule in programming)
Function (rule in programming)
Unviersity of balochistan quetta
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Intro To C++ - Class #19: Functions
Intro To C++ - Class #19: FunctionsIntro To C++ - Class #19: Functions
Intro To C++ - Class #19: Functions
Blue Elephant Consulting
 
Functions
FunctionsFunctions
Functions
Online
 

Similar to Lec16-CS110 Computational Engineering (20)

Functions
FunctionsFunctions
Functions
 
Funtions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the topsFuntions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the tops
 
Functions
FunctionsFunctions
Functions
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
 
Functions_new.pptx
Functions_new.pptxFunctions_new.pptx
Functions_new.pptx
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
 
c++ UNIT II.pptx
c++ UNIT II.pptxc++ UNIT II.pptx
c++ UNIT II.pptx
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
08 subprograms
08 subprograms08 subprograms
08 subprograms
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
Python_Functions_Unit1.pptx
Python_Functions_Unit1.pptxPython_Functions_Unit1.pptx
Python_Functions_Unit1.pptx
 
Function (rule in programming)
Function (rule in programming)Function (rule in programming)
Function (rule in programming)
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Intro To C++ - Class #19: Functions
Intro To C++ - Class #19: FunctionsIntro To C++ - Class #19: Functions
Intro To C++ - Class #19: Functions
 
Functions
FunctionsFunctions
Functions
 

More from Sri Harsha Pamu

Lec09-CS110 Computational Engineering
Lec09-CS110 Computational EngineeringLec09-CS110 Computational Engineering
Lec09-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec08-CS110 Computational Engineering
Lec08-CS110 Computational EngineeringLec08-CS110 Computational Engineering
Lec08-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec07-CS110 Computational Engineering
Lec07-CS110 Computational EngineeringLec07-CS110 Computational Engineering
Lec07-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec06-CS110 Computational Engineering
Lec06-CS110 Computational EngineeringLec06-CS110 Computational Engineering
Lec06-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec04-CS110 Computational Engineering
Lec04-CS110 Computational EngineeringLec04-CS110 Computational Engineering
Lec04-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec03-CS110 Computational Engineering
Lec03-CS110 Computational EngineeringLec03-CS110 Computational Engineering
Lec03-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec02-CS110 Computational Engineering
Lec02-CS110 Computational EngineeringLec02-CS110 Computational Engineering
Lec02-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec01-CS110 Computational Engineering
Lec01-CS110 Computational EngineeringLec01-CS110 Computational Engineering
Lec01-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec1- CS110 Computational Engineering
Lec1- CS110 Computational EngineeringLec1- CS110 Computational Engineering
Lec1- CS110 Computational Engineering
Sri Harsha Pamu
 
Lec25-CS110 Computational Engineering
Lec25-CS110 Computational EngineeringLec25-CS110 Computational Engineering
Lec25-CS110 Computational Engineering
Sri Harsha Pamu
 
Android..imp google
Android..imp googleAndroid..imp google
Android..imp google
Sri Harsha Pamu
 
Android vulnerability study
Android vulnerability studyAndroid vulnerability study
Android vulnerability study
Sri Harsha Pamu
 
Android gui framework
Android gui frameworkAndroid gui framework
Android gui framework
Sri Harsha Pamu
 
Hackernote on gsoc
Hackernote on gsocHackernote on gsoc
Hackernote on gsoc
Sri Harsha Pamu
 

More from Sri Harsha Pamu (16)

Lec13
Lec13Lec13
Lec13
 
Lec09-CS110 Computational Engineering
Lec09-CS110 Computational EngineeringLec09-CS110 Computational Engineering
Lec09-CS110 Computational Engineering
 
Lec08-CS110 Computational Engineering
Lec08-CS110 Computational EngineeringLec08-CS110 Computational Engineering
Lec08-CS110 Computational Engineering
 
Lec07-CS110 Computational Engineering
Lec07-CS110 Computational EngineeringLec07-CS110 Computational Engineering
Lec07-CS110 Computational Engineering
 
Lec06-CS110 Computational Engineering
Lec06-CS110 Computational EngineeringLec06-CS110 Computational Engineering
Lec06-CS110 Computational Engineering
 
Lec04-CS110 Computational Engineering
Lec04-CS110 Computational EngineeringLec04-CS110 Computational Engineering
Lec04-CS110 Computational Engineering
 
Lec03-CS110 Computational Engineering
Lec03-CS110 Computational EngineeringLec03-CS110 Computational Engineering
Lec03-CS110 Computational Engineering
 
Lec02-CS110 Computational Engineering
Lec02-CS110 Computational EngineeringLec02-CS110 Computational Engineering
Lec02-CS110 Computational Engineering
 
Lec01-CS110 Computational Engineering
Lec01-CS110 Computational EngineeringLec01-CS110 Computational Engineering
Lec01-CS110 Computational Engineering
 
Lec1- CS110 Computational Engineering
Lec1- CS110 Computational EngineeringLec1- CS110 Computational Engineering
Lec1- CS110 Computational Engineering
 
Lec25-CS110 Computational Engineering
Lec25-CS110 Computational EngineeringLec25-CS110 Computational Engineering
Lec25-CS110 Computational Engineering
 
Android..imp google
Android..imp googleAndroid..imp google
Android..imp google
 
Android vulnerability study
Android vulnerability studyAndroid vulnerability study
Android vulnerability study
 
Android gui framework
Android gui frameworkAndroid gui framework
Android gui framework
 
Hackernote on gsoc
Hackernote on gsocHackernote on gsoc
Hackernote on gsoc
 
Boot2Gecko Hackernote
Boot2Gecko HackernoteBoot2Gecko Hackernote
Boot2Gecko Hackernote
 

Recently uploaded

June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Ashish Kohli
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
ArianaBusciglio
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Reflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPointReflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPoint
amberjdewit93
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
kitab khulasah nurul yaqin jilid 1 - 2.pptx
kitab khulasah nurul yaqin jilid 1 - 2.pptxkitab khulasah nurul yaqin jilid 1 - 2.pptx
kitab khulasah nurul yaqin jilid 1 - 2.pptx
datarid22
 
MERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDFMERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDF
scholarhattraining
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 

Recently uploaded (20)

June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Reflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPointReflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPoint
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
kitab khulasah nurul yaqin jilid 1 - 2.pptx
kitab khulasah nurul yaqin jilid 1 - 2.pptxkitab khulasah nurul yaqin jilid 1 - 2.pptx
kitab khulasah nurul yaqin jilid 1 - 2.pptx
 
MERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDFMERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDF
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 

Lec16-CS110 Computational Engineering

  • 2. Creative Question • Given a Black box that takes as input two symmetric matrices and outputs the product of the same, use the black box to multiple two arbitrary matrices.
  • 3. a b x c d 0 0 a b 0 0 c d a c 0 0 b d 0 0 e g f h x = p q r s 0 0 e f 0 0 g h e g 0 0 f h 0 0 p r 0 0 q s 0 0 0 0 0 0 u v wx
  • 4. Creative Question • Given a Black box that takes as input a matrix and outputs the square of the same, use the black box to multiple two arbitrary matrices.
  • 5. a b x c d 0 0 a b 0 0 c d e g 0 0 f h 0 0 e g f h x = p q r s 0 0 a b 0 0 c d e g 0 0 f h 0 0 p r 0 0 q s 0 0 0 0 0 0 u v wx
  • 6. Creative Question • Given a Black box that takes as input a lower triangular matrix and an upper triangular matrix and outputs the product of the same, use the black box to multiple two arbitrary square matrices.
  • 7. a b x c d 0 0 0 0 0 0 0 0 a b 0 0 c d 0 0 e g f h x = p q r s 0 0 e g 0 0 f h 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 p r 0 0 q s
  • 8. Creative Question • Given a Black box that takes as input two lower triangular matrices and outputs the product of the same, use the black box to multiple two arbitrary square matrices.
  • 9. a b x c d 000000 000000 000000 000000 00ab00 00cd00 x e g f h = 000000 000000 eg0000 f h0000 000000 000000 p q r s = 000000 000000 000000 000000 pq0000 r s0000
  • 10. Functions = outsourcing • Break large computing tasks into small ones • Helps you to build on what others have done • You and others write functions • When you want to build a program, find out how to use the function and use it. • Use standard functions provided by the library. • You are hidden from the implementation • Example – you don’t have to worry about how pow(m,n) is implemented • As engineers from different disciplines you will use and develop different set of functions
  • 11. Modular Programming Subprograms functions in C, C++, procedures and functions in Pascal facilitate modular programming Overall task is divided into modules Each module - a collection of subprograms a subprogram may be invoked at several points A commonly used computation hiding the implementation incorporating changes easier
  • 12. Example of function sets • String manipulation • Mathematical • Finite Element Method • Used in structural analysis by Mechanical, Civil, Aero, etc. for stress calculations etc. • Most function libraries cost a lot • Business opportunity – identify functions that are useful to you area of study, create libraries. • Functions for use in different software. • Say, functions for web services
  • 13. Basics • Function is a part of your program. • It cannot be a part of any other function • Main() is a function: it is the main function. Execution starts there or the control flow starts there • From there it can flow from one function to another, return after a computation with some values, probably, and then flow on. • Transfer of control is affected by calling a function • • • • • • • With a function call, we pass some parameters These parameters are used within the function A value is computed The value is returned to the function which initiated the call The calling function can ignore the value returned It could use it in some other computation A function could call itself, these are called recursive function calls
  • 14. Add function to your Program • A program was a set of variables, and assignments to variables • Now add function to it. • • • • Set of variables Some functions including main() Communicating values to each other Computing and returning values for each other • Instead of one long program, we now write structured program composed of functions
  • 15. Features • C program -- a collection of functions – function main ( ) - mandatory - program starts here. • C is not a block structured language – a function can not be defined inside another function – only variables can be defined in functions / blocks • Variables can be defined outside of all functions – global variables - accessible to all functions – a means of sharing data between functions - caution • Recursion is possible – a function can call itself - directly or indirectly
  • 17. Function Definition in C return-type function-name (argument declarations) { variable/constant declarations and No function statements } declarations here! Arguments or parameters: the means of giving input to the function type and name of arguments are declared names are formal - local to the function Return Value: for giving the output value return ( expression ); -- optional Invoking a function: funct-name(exp1,exp2,…,expn) Matching the number and type of arguments
  • 18. Function Prototype • defines – the number of parameters, type of each parameter, – type of the return value of a function • used by the compiler to check the usage – prevents execution-time errors • function prototype of power function – int power ( int, int ); – no need for naming the parameters • function prototypes - given in the beginning
  • 19. Power Function #include <stdio.h> function prototype int power (int, int); -- Computes the nth power of base. main () { for ( int i = 0; i < 20; i ++ ) printf(“%d %d %dn”, i, power(3,i), power(-4,i);} int power (int base, int n) { int i, p = 1; for ( i = 1; i <= n ; i ++) p = p ∗ base; return p; } A block Invocation with arguments
  • 20. Calling Power Function with i=3 printf(“%d %d %dn”, i, power(3,i), power(-4,i);} 27 int power (int base, int n) { int i, p = 1; for ( i = 1; i <= n ; i ++) p = p ∗ base; return p; } -64 int power (int base, int n) { int i, p = 1; for ( i = 1; i <= n ; i ++) p = p ∗ base; return p; }
  • 21. Thank You • For Exam – Bring BOTH your Institute ID card and RFID card - else you shall not be permitted to write the exam. • All the Best