SlideShare a Scribd company logo
1 of 13
Prepared by
Mohammed Sikander
Technical Lead
Cranes Software International Limited
 What is a function?
 Write the Syntax of Function?
 What are the benefits of using a function?
 Is main a user-defined or library function?
 Explain the difference between call by value
and call by reference(address)?
mohammed.sikander@cranessoftware.com 2
 Name some Library (built-in) functions used
by you till now?
mohammed.sikander@cranessoftware.com 3
 SYNOPSIS
#include <math.h>
double sqrt(double x);
mohammed.sikander@cranessoftware.com 4
#include <stdio.h>
#include <math.h>
int main( )
{
float res = sqrt(16);
printf(“ %f “ , res);
}
SYNOPSIS
#include <math.h>
double pow(double x, double y);
mohammed.sikander@cranessoftware.com 5
int main( )
{
int x , y;
printf(“Enter two numbers : “);
scanf(“ %d %d” , &x, &y);
int res = pow ( x , y);
printf(“ %d “ , res);
}
#include <ctype.h>
int isupper(int c);
It checks whether the given character is uppercase or not. Returns o is not
non-zero otherwise
mohammed.sikander@cranessoftware.com 6
#include <ctype.h>
int main( )
{
char c;
printf(“Enter a character : “);
scanf(“ %c”,&c);
int res = isupper(c) ;
if(res == 0)
printf(“Not a Upper Case Character “);
else
printf(“UPPERCASECharacter “);
}
 Now we have learned how to call a function.
 Now lets write our (user-defined) function.
mohammed.sikander@cranessoftware.com 7
Returntype functionName(parameters)
{
body
}
Every parameter will have type and name
The parameter list can be empty
int main( )
{
------
}
mohammed.sikander@cranessoftware.com 8
 Write a factorial function which accepts a number and returns the
factorial of it.
 Eg: Input Output
5 120
3 6
mohammed.sikander@cranessoftware.com 9
int factorial( int num)
{
int res = 1;
for(i = 2 ; i <= num ; i++)
res = res * i;
return res;
}
int main( )
{
int res = factorial(5);
printf(“ %d n“ , res);
res = factorial(3);
printf(“ %d n“ , res);
}
int main( )
{
int n , r;
printf(“Enter the value of n and r : “);
scanf(“ %d %d”,&n,&r);
int nfact = factorial(n);
int rfact = factorial(r);
int nrfact = factorial(n - r);
int ncr = nfact / (rfact * nrfact);
int npr = nfact / nrfact;
printf(“ %d C %d = %d n“ , n , r , ncr);
printf(“ %d P %d = %d n“ , n , r , npr);
}
mohammed.sikander@cranessoftware.com 10
int gcd(int a,int b)
{
int rem;
while(b != 0)
{
rem = a % b;
a = b;
b = rem;
}
return a;
}
mohammed.sikander@cranessoftware.com 11
int main()
{
int a , b;
printf(“Enter two numbers : “);
scanf(“ %d %d”,&a,&b);
int res = gcd(a , b);
printf(“GCD(%d , %d) = %d”,a , b , res);
int lcm = a * b / res;
printf(“LCM(%d ,%d) = %d”,a , b , lcm);
}
#include <stdbool.h>
bool isprime(int num)
{
int count = 0;
for(int i = 2 ; i < num - 1 ; i++)
{
int rem = num % i;
if(rem == 0)
count++;
}
return count == 0?true:false;
}
mohammed.sikander@cranessoftware.com 12
int main( )
{
int num ;
bool result;
printf("Enter a number : ");
scanf(" %d" , &num);
if(res == true)
printf("Prime ");
else
printf("Not Prime ");
}
mohammed.sikander@cranessoftware.com 13
int main( )
{
int n1 , n2;
bool result;
printf("Enter the start and end range : ");
scanf(" %d %d" , &n1 , n2);
for(int i = n1 ; i <= n2 ; i++)
{
bool res = isprime( i );
if(res == true)
printf(“ %d “ , i);
}
}

More Related Content

What's hot (20)

Inheritance and polymorphism
Inheritance and polymorphismInheritance and polymorphism
Inheritance and polymorphism
 
Static and const members
Static and const membersStatic and const members
Static and const members
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Implementation of c string functions
Implementation of c string functionsImplementation of c string functions
Implementation of c string functions
 
C programs
C programsC programs
C programs
 
C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st Study
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
C++ file
C++ fileC++ file
C++ file
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
 
C++ programs
C++ programsC++ programs
C++ programs
 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
Introduction to c part 2
 
week-18x
week-18xweek-18x
week-18x
 
Double linked list
Double linked listDouble linked list
Double linked list
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
 
Basic Programs of C++
Basic Programs of C++Basic Programs of C++
Basic Programs of C++
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd Study
 
4. chapter iii
4. chapter iii4. chapter iii
4. chapter iii
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
 

Viewers also liked

New definition for being fit - Just Dance
New definition for being fit - Just DanceNew definition for being fit - Just Dance
New definition for being fit - Just DancePriyadarshani Jain
 
Standar asuhan keperawatan klien dengan halusinasi
Standar asuhan keperawatan klien dengan halusinasiStandar asuhan keperawatan klien dengan halusinasi
Standar asuhan keperawatan klien dengan halusinasiAang Triyadi
 
Kuukausittainen matkailutilasto Etelä-Savo syyskuu 2015
Kuukausittainen matkailutilasto Etelä-Savo syyskuu 2015Kuukausittainen matkailutilasto Etelä-Savo syyskuu 2015
Kuukausittainen matkailutilasto Etelä-Savo syyskuu 2015Matkailufoorumi
 
Data structures in C Singlly Linked List Concept
Data structures in C  Singlly Linked List ConceptData structures in C  Singlly Linked List Concept
Data structures in C Singlly Linked List Conceptayman diab
 
MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU HAMIL PADA NY “S” DENGAN ...
MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU HAMIL PADA NY “S” DENGAN ...MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU HAMIL PADA NY “S” DENGAN ...
MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU HAMIL PADA NY “S” DENGAN ...Warnet Raha
 
Successful Tourism Strategic Plans for Destinations - Dr. Harsh Varma
Successful Tourism Strategic Plans for Destinations - Dr. Harsh VarmaSuccessful Tourism Strategic Plans for Destinations - Dr. Harsh Varma
Successful Tourism Strategic Plans for Destinations - Dr. Harsh VarmaFEST
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examplesbindur87
 

Viewers also liked (13)

3 palestra sergio 2012
3 palestra sergio 20123 palestra sergio 2012
3 palestra sergio 2012
 
Redes sociales
Redes socialesRedes sociales
Redes sociales
 
New definition for being fit - Just Dance
New definition for being fit - Just DanceNew definition for being fit - Just Dance
New definition for being fit - Just Dance
 
Colleen Kolakowski Resume 12-27-2016
Colleen Kolakowski Resume 12-27-2016Colleen Kolakowski Resume 12-27-2016
Colleen Kolakowski Resume 12-27-2016
 
Pointer level 2
Pointer   level 2Pointer   level 2
Pointer level 2
 
Standar asuhan keperawatan klien dengan halusinasi
Standar asuhan keperawatan klien dengan halusinasiStandar asuhan keperawatan klien dengan halusinasi
Standar asuhan keperawatan klien dengan halusinasi
 
Resti fiks fdf
Resti fiks fdfResti fiks fdf
Resti fiks fdf
 
Kuukausittainen matkailutilasto Etelä-Savo syyskuu 2015
Kuukausittainen matkailutilasto Etelä-Savo syyskuu 2015Kuukausittainen matkailutilasto Etelä-Savo syyskuu 2015
Kuukausittainen matkailutilasto Etelä-Savo syyskuu 2015
 
Data structures in C Singlly Linked List Concept
Data structures in C  Singlly Linked List ConceptData structures in C  Singlly Linked List Concept
Data structures in C Singlly Linked List Concept
 
MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU HAMIL PADA NY “S” DENGAN ...
MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU HAMIL PADA NY “S” DENGAN ...MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU HAMIL PADA NY “S” DENGAN ...
MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU HAMIL PADA NY “S” DENGAN ...
 
Intan. iii.a
Intan. iii.aIntan. iii.a
Intan. iii.a
 
Successful Tourism Strategic Plans for Destinations - Dr. Harsh Varma
Successful Tourism Strategic Plans for Destinations - Dr. Harsh VarmaSuccessful Tourism Strategic Plans for Destinations - Dr. Harsh Varma
Successful Tourism Strategic Plans for Destinations - Dr. Harsh Varma
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
 

Similar to Function basics (20)

Pointer basics
Pointer basicsPointer basics
Pointer basics
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
7 functions
7  functions7  functions
7 functions
 
C Programming
C ProgrammingC Programming
C Programming
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
 
Functions
FunctionsFunctions
Functions
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using c
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
C programming function
C  programming functionC  programming function
C programming function
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
Functions
FunctionsFunctions
Functions
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solution
 
C lab
C labC lab
C lab
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Functions
FunctionsFunctions
Functions
 
CHAPTER 6
CHAPTER 6CHAPTER 6
CHAPTER 6
 

Recently uploaded

WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Eraconfluent
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2WSO2
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 

Recently uploaded (20)

WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 

Function basics

  • 1. Prepared by Mohammed Sikander Technical Lead Cranes Software International Limited
  • 2.  What is a function?  Write the Syntax of Function?  What are the benefits of using a function?  Is main a user-defined or library function?  Explain the difference between call by value and call by reference(address)? mohammed.sikander@cranessoftware.com 2
  • 3.  Name some Library (built-in) functions used by you till now? mohammed.sikander@cranessoftware.com 3
  • 4.  SYNOPSIS #include <math.h> double sqrt(double x); mohammed.sikander@cranessoftware.com 4 #include <stdio.h> #include <math.h> int main( ) { float res = sqrt(16); printf(“ %f “ , res); }
  • 5. SYNOPSIS #include <math.h> double pow(double x, double y); mohammed.sikander@cranessoftware.com 5 int main( ) { int x , y; printf(“Enter two numbers : “); scanf(“ %d %d” , &x, &y); int res = pow ( x , y); printf(“ %d “ , res); }
  • 6. #include <ctype.h> int isupper(int c); It checks whether the given character is uppercase or not. Returns o is not non-zero otherwise mohammed.sikander@cranessoftware.com 6 #include <ctype.h> int main( ) { char c; printf(“Enter a character : “); scanf(“ %c”,&c); int res = isupper(c) ; if(res == 0) printf(“Not a Upper Case Character “); else printf(“UPPERCASECharacter “); }
  • 7.  Now we have learned how to call a function.  Now lets write our (user-defined) function. mohammed.sikander@cranessoftware.com 7
  • 8. Returntype functionName(parameters) { body } Every parameter will have type and name The parameter list can be empty int main( ) { ------ } mohammed.sikander@cranessoftware.com 8
  • 9.  Write a factorial function which accepts a number and returns the factorial of it.  Eg: Input Output 5 120 3 6 mohammed.sikander@cranessoftware.com 9 int factorial( int num) { int res = 1; for(i = 2 ; i <= num ; i++) res = res * i; return res; } int main( ) { int res = factorial(5); printf(“ %d n“ , res); res = factorial(3); printf(“ %d n“ , res); }
  • 10. int main( ) { int n , r; printf(“Enter the value of n and r : “); scanf(“ %d %d”,&n,&r); int nfact = factorial(n); int rfact = factorial(r); int nrfact = factorial(n - r); int ncr = nfact / (rfact * nrfact); int npr = nfact / nrfact; printf(“ %d C %d = %d n“ , n , r , ncr); printf(“ %d P %d = %d n“ , n , r , npr); } mohammed.sikander@cranessoftware.com 10
  • 11. int gcd(int a,int b) { int rem; while(b != 0) { rem = a % b; a = b; b = rem; } return a; } mohammed.sikander@cranessoftware.com 11 int main() { int a , b; printf(“Enter two numbers : “); scanf(“ %d %d”,&a,&b); int res = gcd(a , b); printf(“GCD(%d , %d) = %d”,a , b , res); int lcm = a * b / res; printf(“LCM(%d ,%d) = %d”,a , b , lcm); }
  • 12. #include <stdbool.h> bool isprime(int num) { int count = 0; for(int i = 2 ; i < num - 1 ; i++) { int rem = num % i; if(rem == 0) count++; } return count == 0?true:false; } mohammed.sikander@cranessoftware.com 12 int main( ) { int num ; bool result; printf("Enter a number : "); scanf(" %d" , &num); if(res == true) printf("Prime "); else printf("Not Prime "); }
  • 13. mohammed.sikander@cranessoftware.com 13 int main( ) { int n1 , n2; bool result; printf("Enter the start and end range : "); scanf(" %d %d" , &n1 , n2); for(int i = n1 ; i <= n2 ; i++) { bool res = isprime( i ); if(res == true) printf(“ %d “ , i); } }