Documente Academic
Documente Profesional
Documente Cultură
An Assignment
Submitted to
DAUD T. POLAO
Faculty, Department of Information Technology
RC- Al Khwarizmi International College Foundation Inc.
Marawi City
In partial fulfillment
Of the Requirements for the Course
IT21 (Fundamentals of Programming and Data Base)
Submitted By
ALMERAH H. BASER
August 2019
FUNCTIONS AND ITS STRUCTURES
What is function?
It is a group of statements that together performs a task. Every C++ program has at
least one function, which is main(), and all the most trivial programs can define
additional functions.
A function declaration tells the compiler about a function’s name, return type, and
parameters.
Structure
C++ Program to assign data to members of a structure variable and display it. Here
a structure P erson is declared which has three members name, age and salary.
Inside main() function, a structure variable p1 is defined. You can divide up your
code into separate functions. How you divide up your code among different
functions is up to you, but logically the division usually is so each function performs
a specific task.
Example
#include <iostream>
using namespace std;
Int main()
Return 0;
Output
100
Two types of in C++:
Library functions
User-defined functions
Structure
Library functions include standard input/output (stdio.h), string manipulation
(string.h), math functions (math.h), and date and time functions (time.h). We
learned that the functions for stdio.h include the following: printf() is output to the
screen.
Examples
Example 1:
#include <iostream>
#include <cmath>
square_root = sqrt(number);
cout <<”Square root of “ << number << “ = “ << square_root;
return 0;
}
Output
Enter a number: 26
Square root of 26 = 5.09902
Example 2:
#include <stdio.h>
#include <math.h>
int main()
{
float num, root;
printf (“Enter a number: “);
Spscanf (“%f”, &num);
return o;
Output
Enter a number: 12
Square root of 12.00 = 3.46
Structure
It is a block of code that performs a specific task. In which C allows you to define
functions according to your needs.
Examples
Example 1:
#include <iostream>
using namespace std;
int main()
{
Iint num 1, num 2, sum;
cout<< ”Enter two number to add:”;
cin >> num 1 >> num 2;
return add;
}
Output
Enters two integers: 8 – 4
Sum = 4
Example 2:
#include <stdio.h>
int add_numbers (int a, int b);
int main()
{
return 0;
}