SlideShare une entreprise Scribd logo
1  sur  91
Télécharger pour lire hors ligne
Unit:3
Loops & Functions
Programs
1. Write a program in C to display the
first 10 natural numbers.
2. Write a C program to find the sum
of first 10 natural numbers
3. Write a program in C to display the cube
of the number up to given an integer
4. Write a program in C to display the
multiplication table of a given integer.
5. Write a C program to calculate the
factorial of a given number
6. Display the sum of the series [ 9 +
99 + 999 + 9999 ...]
7. Write a program in C to display the n terms of
square natural number and their sum.
8. Write a c program to check whether a
given number is a perfect number or not.
• Write a program in C to display the n terms of
odd natural number and their sum.
• Write a program in C to display the n terms of
even natural number and their sum.
• Write a C program to determine whether a
given number is prime or not.
• To find sum of numbers from m to n.
• To count number of digits in a number.
• To find whether a number is Armstrong number
or not.
• To find reverse of a number.
• To find whether a number is palindrome or not.
• To find decimal equivalent of a Binary number.
• To find Binary equivalent of a decimal number.
• To print various patterns.
Storage Classes
in C
• It defines the scope(visibility) and a lifetime of
variables and/or functions within a program.
1. Scope: where the value of the variable would
be available inside a program.
2. default initial value: if we do not explicitly
initialize that variable, what will be its default
initial value.
3. lifetime of that variable: for how long will
that variable exist.
• The following storage classes are most often
used in C programming:
1. Automatic variables
2. External variables
3. Static variables
4. Register variables
1. Automatic variables: ”auto”
• Scope: Variable defined with auto storage class are
local to the function block inside which they are
defined.
• Default Initial Value: Any random value i.e garbage
value.
• Lifetime: Till the end of the function/method block
where the variable is defined.
• by default an automatic variable.
• Automatic variables can also be called local variables
because they are local to a function.
2. Register Storage Class: “register”
• Scope: Local to the function in which it is declared.
• Default initial value: garbage value
• Lifetime: Till the end of function block.
• Same as auto except, Store the variable in CPU
register instead of memory. We should
use register storage class only for those variables that
are used in our program very often. CPU registers are
limited and thus should be used carefully.
• Syntax : register int number;
3. External or Global variable: “extern”
• Scope: Global (everywhere in the program).
• Default initial value: 0(zero).
• Lifetime: Till the program doesn't finish its execution,
you can access global variables.
• These variables are not bound by any function, they
are available everywhere.
• variables, which are not needed till the end of the
program, will still occupy the memory and thus,
memory will be wasted.
• The extern modifier is most commonly used when
there are two or more files sharing the same global
variables or functions.
4. Static variables: “static”
• Scope: Local to the block in which the variable
is defined
• Default initial value: 0(Zero).
• Lifetime: Till the whole program doesn't finish
its execution.
• We should use static storage class only when
we want the value of the variable to remain
same every time we call it using different
function calls
A function is a set of statements that take inputs, do
some specific computation and produces output.
• The idea is to put some commonly or repeatedly done
task together and make a function, so that instead of
writing the same code again and again for different
inputs, we can call the function.
• Each function perform some specific task.
• Every C program has at least one function
main(). Execution of a program starts from
main().
• A function can also be referred as a method or
sub-routine or procedure etc.
• A function divides complex problem into small
components, makes program easy to
understand and use.
Function Declaration
• Function declaration tells compiler about -
1. number of parameters function takes,
2. data-types of parameters and
3. return type of function.
• Putting parameter names in function declaration is
optional in function declaration, but it is necessary to
put them in definition.
Function Definition
• Actual code of the function, which does some
specific task.
• Function definition contains function header
and function body.
#include <stdio.h>
#include <conio.h>
int max(int x, int y) //function declaration with definition
{ if (x > y)
return x;
else
return y;
}
int main() // main function with “int” return type
{ int m, a = 10, b = 20;
// Calling above function to find max of 'a' and 'b'
m = max(a, b);
printf("m is %d", m);
return 0;
#include <stdio.h>
#include <conio.h>
int max(int , int ); //function declaration
int main() // main function with “int” return type
{ int m, a = 10, b = 20;
// Calling above function to find max of 'a' and 'b'
m = max(a, b);
printf("m is %d", m);
return 0;
}
int max(int x , int y) //function definition
{ if (x > y)
return x;
else
return y;
}
Return Statement
• It terminates the execution of a function and
returns a value to the calling function.
• Program control is transferred to the calling
function after return statement.
• It is always recommended to declare a function before
it is used.
• In C, we can do both declaration and definition at same
place, like done in the previous example program.
• C also allows to declare and define functions separately,
this is specially needed in case of library functions.
• The library functions are declared in header files and
defined in library files.
return_type function_name( Parameter_list ); //function declaration
return_type main() // main function
{
Body of main function
function_name ( Actual Arguments); // Calling above function
}
return_type function_name( Formal Arguments or parameters ) //function
definition
{
Body of user defined function
}
Ways of defining a function
1.No arguments and No return Value:
#include <stdio.h>
void add(void ); //function declaration
void main() // main function with “int” return type
{ clrscr();
add();
getch();
}
Void add(void) //function definition
{ int x,y,z;
printf(“Enter numbers”);
Scanf(“%dn%d”,&x,&y);
z=x+y;
printf(“%d”,z);
}
2.Function with arguments and
no return Value:
#include <stdio.h>
void add(int,int); //function declaration
void main() // main function with “int” return type
{
int a, b;
clrscr();
printf(“Enter two numbers”);
Scanf(“%dn%d”,&a,&b);
add(a,b);
getch();
}
Void add(int x, int y) //function definition
{ int z;
z=x+y;
printf(“%d”,z);
}
3.Function with no arguments and
with return Value:
#include <stdio.h>
void add(void); //function declaration
void main() // main function with “int” return type
{
int c;
clrscr();
c= add();
printf(“%d”,c);
getch();
}
Void add() //function definition
{ int x,y,z;
printf(“Enter two numbers”);
Scanf(“%dn%d”,&x,&y);
z=x+y;
return z;
}
4.Function with arguments and
Return Value:
#include <stdio.h>
void add(int,int); //function declaration
void main() // main function with “int” return type
{
int a, b,c;
clrscr();
printf(“Enter two numbers”);
Scanf(“%dn%d”,&a,&b);
c= add(a,b);
printf(“%d”,c);
getch();
}
Void add(int x, int y) //function definition
{ int z;
z=x+y;
return z;
}
Calling of a function
• In this, values of actual parameters are copied
to function’s formal parameters.
• Two types of parameters are stored in
different memory locations.
• So any changes made inside functions are not
reflected in actual parameters of caller.
• Both actual and formal parameters refer to
same locations, so any changes made inside
the function are actually reflected in actual
parameters of caller.
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii
Unit iii

Contenu connexe

Tendances

Programming in C Session 1
Programming in C Session 1Programming in C Session 1
Programming in C Session 1Prerna Sharma
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lexAnusuya123
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III TermAndrew Raj
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of CSuchit Patel
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationAkhil Kaushik
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programmingnmahi96
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2Prerna Sharma
 
Symbol table management and error handling in compiler design
Symbol table management and error handling in compiler designSymbol table management and error handling in compiler design
Symbol table management and error handling in compiler designSwati Chauhan
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programmingavikdhupar
 

Tendances (18)

Programming in C Session 1
Programming in C Session 1Programming in C Session 1
Programming in C Session 1
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
 
Clanguage
ClanguageClanguage
Clanguage
 
C language ppt
C language pptC language ppt
C language ppt
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
 
Lexical analysis-using-lex
Lexical analysis-using-lexLexical analysis-using-lex
Lexical analysis-using-lex
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
 
C++ version 1
C++  version 1C++  version 1
C++ version 1
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
C++ Version 2
C++  Version 2C++  Version 2
C++ Version 2
 
Symbol table management and error handling in compiler design
Symbol table management and error handling in compiler designSymbol table management and error handling in compiler design
Symbol table management and error handling in compiler design
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
 

Similaire à Unit iii (20)

Functions in c
Functions in cFunctions in c
Functions in c
 
Functions in c
Functions in cFunctions in c
Functions in c
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
Functions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxFunctions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptx
 
visiblity and scope.pptx
visiblity and scope.pptxvisiblity and scope.pptx
visiblity and scope.pptx
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 
Functions
FunctionsFunctions
Functions
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
1.6 Function.pdf
1.6 Function.pdf1.6 Function.pdf
1.6 Function.pdf
 
Unit 3 (1)
Unit 3 (1)Unit 3 (1)
Unit 3 (1)
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
 
Functions
Functions Functions
Functions
 
Functions in C.pptx
Functions in C.pptxFunctions in C.pptx
Functions in C.pptx
 
Functions
FunctionsFunctions
Functions
 

Plus de SHIKHA GAUTAM

Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemorySHIKHA GAUTAM
 
Distributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionDistributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionSHIKHA GAUTAM
 
Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance SHIKHA GAUTAM
 
Type conversion in c
Type conversion in cType conversion in c
Type conversion in cSHIKHA GAUTAM
 
3. basic organization of a computer
3. basic organization of a computer3. basic organization of a computer
3. basic organization of a computerSHIKHA GAUTAM
 
Generations of computer
Generations of computerGenerations of computer
Generations of computerSHIKHA GAUTAM
 
Warehouse Planning and Implementation
Warehouse Planning and ImplementationWarehouse Planning and Implementation
Warehouse Planning and ImplementationSHIKHA GAUTAM
 
Dbms Introduction and Basics
Dbms Introduction and BasicsDbms Introduction and Basics
Dbms Introduction and BasicsSHIKHA GAUTAM
 

Plus de SHIKHA GAUTAM (15)

Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared Memory
 
Distributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionDistributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock Detection
 
Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance
 
Unit 4
Unit 4Unit 4
Unit 4
 
Unit ii_KCS201
Unit ii_KCS201Unit ii_KCS201
Unit ii_KCS201
 
Type conversion in c
Type conversion in cType conversion in c
Type conversion in c
 
4. algorithm
4. algorithm4. algorithm
4. algorithm
 
3. basic organization of a computer
3. basic organization of a computer3. basic organization of a computer
3. basic organization of a computer
 
Generations of computer
Generations of computerGenerations of computer
Generations of computer
 
c_programming
c_programmingc_programming
c_programming
 
Data Mining
Data MiningData Mining
Data Mining
 
Warehouse Planning and Implementation
Warehouse Planning and ImplementationWarehouse Planning and Implementation
Warehouse Planning and Implementation
 
Data Warehousing
Data WarehousingData Warehousing
Data Warehousing
 
Dbms Introduction and Basics
Dbms Introduction and BasicsDbms Introduction and Basics
Dbms Introduction and Basics
 
DBMS
DBMSDBMS
DBMS
 

Dernier

Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 

Dernier (20)

Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 

Unit iii

  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 20. 1. Write a program in C to display the first 10 natural numbers.
  • 21. 2. Write a C program to find the sum of first 10 natural numbers
  • 22. 3. Write a program in C to display the cube of the number up to given an integer
  • 23. 4. Write a program in C to display the multiplication table of a given integer.
  • 24. 5. Write a C program to calculate the factorial of a given number
  • 25. 6. Display the sum of the series [ 9 + 99 + 999 + 9999 ...]
  • 26. 7. Write a program in C to display the n terms of square natural number and their sum.
  • 27.
  • 28. 8. Write a c program to check whether a given number is a perfect number or not.
  • 29. • Write a program in C to display the n terms of odd natural number and their sum. • Write a program in C to display the n terms of even natural number and their sum. • Write a C program to determine whether a given number is prime or not. • To find sum of numbers from m to n.
  • 30. • To count number of digits in a number. • To find whether a number is Armstrong number or not. • To find reverse of a number. • To find whether a number is palindrome or not. • To find decimal equivalent of a Binary number. • To find Binary equivalent of a decimal number. • To print various patterns.
  • 32. • It defines the scope(visibility) and a lifetime of variables and/or functions within a program. 1. Scope: where the value of the variable would be available inside a program. 2. default initial value: if we do not explicitly initialize that variable, what will be its default initial value. 3. lifetime of that variable: for how long will that variable exist.
  • 33. • The following storage classes are most often used in C programming: 1. Automatic variables 2. External variables 3. Static variables 4. Register variables
  • 34. 1. Automatic variables: ”auto” • Scope: Variable defined with auto storage class are local to the function block inside which they are defined. • Default Initial Value: Any random value i.e garbage value. • Lifetime: Till the end of the function/method block where the variable is defined. • by default an automatic variable. • Automatic variables can also be called local variables because they are local to a function.
  • 35.
  • 36. 2. Register Storage Class: “register” • Scope: Local to the function in which it is declared. • Default initial value: garbage value • Lifetime: Till the end of function block. • Same as auto except, Store the variable in CPU register instead of memory. We should use register storage class only for those variables that are used in our program very often. CPU registers are limited and thus should be used carefully. • Syntax : register int number;
  • 37. 3. External or Global variable: “extern” • Scope: Global (everywhere in the program). • Default initial value: 0(zero). • Lifetime: Till the program doesn't finish its execution, you can access global variables. • These variables are not bound by any function, they are available everywhere. • variables, which are not needed till the end of the program, will still occupy the memory and thus, memory will be wasted. • The extern modifier is most commonly used when there are two or more files sharing the same global variables or functions.
  • 38.
  • 39.
  • 40. 4. Static variables: “static” • Scope: Local to the block in which the variable is defined • Default initial value: 0(Zero). • Lifetime: Till the whole program doesn't finish its execution. • We should use static storage class only when we want the value of the variable to remain same every time we call it using different function calls
  • 41.
  • 42.
  • 43.
  • 44. A function is a set of statements that take inputs, do some specific computation and produces output. • The idea is to put some commonly or repeatedly done task together and make a function, so that instead of writing the same code again and again for different inputs, we can call the function. • Each function perform some specific task.
  • 45. • Every C program has at least one function main(). Execution of a program starts from main(). • A function can also be referred as a method or sub-routine or procedure etc. • A function divides complex problem into small components, makes program easy to understand and use.
  • 46. Function Declaration • Function declaration tells compiler about - 1. number of parameters function takes, 2. data-types of parameters and 3. return type of function. • Putting parameter names in function declaration is optional in function declaration, but it is necessary to put them in definition.
  • 47. Function Definition • Actual code of the function, which does some specific task. • Function definition contains function header and function body.
  • 48. #include <stdio.h> #include <conio.h> int max(int x, int y) //function declaration with definition { if (x > y) return x; else return y; } int main() // main function with “int” return type { int m, a = 10, b = 20; // Calling above function to find max of 'a' and 'b' m = max(a, b); printf("m is %d", m); return 0;
  • 49. #include <stdio.h> #include <conio.h> int max(int , int ); //function declaration int main() // main function with “int” return type { int m, a = 10, b = 20; // Calling above function to find max of 'a' and 'b' m = max(a, b); printf("m is %d", m); return 0; } int max(int x , int y) //function definition { if (x > y) return x; else return y; }
  • 50. Return Statement • It terminates the execution of a function and returns a value to the calling function. • Program control is transferred to the calling function after return statement.
  • 51. • It is always recommended to declare a function before it is used. • In C, we can do both declaration and definition at same place, like done in the previous example program. • C also allows to declare and define functions separately, this is specially needed in case of library functions. • The library functions are declared in header files and defined in library files.
  • 52.
  • 53.
  • 54.
  • 55. return_type function_name( Parameter_list ); //function declaration return_type main() // main function { Body of main function function_name ( Actual Arguments); // Calling above function } return_type function_name( Formal Arguments or parameters ) //function definition { Body of user defined function }
  • 56. Ways of defining a function
  • 57. 1.No arguments and No return Value: #include <stdio.h> void add(void ); //function declaration void main() // main function with “int” return type { clrscr(); add(); getch(); } Void add(void) //function definition { int x,y,z; printf(“Enter numbers”); Scanf(“%dn%d”,&x,&y); z=x+y; printf(“%d”,z); }
  • 58. 2.Function with arguments and no return Value: #include <stdio.h> void add(int,int); //function declaration void main() // main function with “int” return type { int a, b; clrscr(); printf(“Enter two numbers”); Scanf(“%dn%d”,&a,&b); add(a,b); getch(); } Void add(int x, int y) //function definition { int z; z=x+y; printf(“%d”,z); }
  • 59. 3.Function with no arguments and with return Value: #include <stdio.h> void add(void); //function declaration void main() // main function with “int” return type { int c; clrscr(); c= add(); printf(“%d”,c); getch(); } Void add() //function definition { int x,y,z; printf(“Enter two numbers”); Scanf(“%dn%d”,&x,&y); z=x+y; return z; }
  • 60. 4.Function with arguments and Return Value: #include <stdio.h> void add(int,int); //function declaration void main() // main function with “int” return type { int a, b,c; clrscr(); printf(“Enter two numbers”); Scanf(“%dn%d”,&a,&b); c= add(a,b); printf(“%d”,c); getch(); } Void add(int x, int y) //function definition { int z; z=x+y; return z; }
  • 61. Calling of a function
  • 62.
  • 63.
  • 64.
  • 65.
  • 66. • In this, values of actual parameters are copied to function’s formal parameters. • Two types of parameters are stored in different memory locations. • So any changes made inside functions are not reflected in actual parameters of caller.
  • 67.
  • 68.
  • 69. • Both actual and formal parameters refer to same locations, so any changes made inside the function are actually reflected in actual parameters of caller.