Tuesday, 1 August 2017

Write a C++ program by using function that make a table

Write a C++ program by using function that make a table.

What is a Function ?

A Function is a group of statements that collectively perform a task. Every C++ program has at the least one Function, which is main(), and all the maximum trivial programs can define extra Functions. You can divide up your code into separate Functions.

Syntax Of Function:

The general form of a C++ function definition is as follows:

return_type function_name (parameters)
{
// function_body
}

·       1 -  return_type : suggests what the function will return. It can be int, char, some pointer or even a class object. There can be functions which does not return anything, they are mentioned with void.       
·       2 -  Function_name : This is the actual name of the function. The function name and the parameter list together constitute the function signature.
·       3 -  Parameters : are variables to hold values of arguments passed while function is called. A function may or may not contain parameter list.

Code:

#include <iostream>
using namespace std;
void starline(); //function declaration
// (prototype)
int main()
{
starline(); //call to function
cout << "Data type Range" << endl;
starline(); //call to function
cout << "char -128 to 127" << endl
<< "short -32,768 to 32,767" << endl
<< "int System dependent" << endl
<< "long -2,147,483,648 to 2,147,483,647" << endl;
starline(); //call to function
return 0;
}
//--------------------------------------------------------------
// starline()
// function definition
void starline() //function declarator
{
for(int s=0; s<45; s++) //function body
cout << "*";
cout << endl;
}

Output:














Try it yourself.
If you have any problem you can tell me on comment box i will help you.
thanks.

Viral Programs

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.

2 comments:

  1. nice article brother keep up good work
    http://www.nicedayindia.com/2017/07/jio-4g_28.html

    ReplyDelete