user defined funcions in C++

 Function with no arguments and no return value

#include<iostream>
using namespace std;
void fact()
{
int n;
long int f=1;
cout<<"enter a no";
cin>>n;
for(int i=1;i<=n;i++)
f=f*i;
cout<<"factorial of "<<n<<"=" <<f;
}

int main()
{
    fact();
    return 0;
}
 
Function with no arguments and a return value

#include<iostream>
using namespace std;
int fact()
{
int n;
long int f=1;
cout<<"enter a no";
cin>>n;
for(int i=1;i<=n;i++)
f=f*i;
return f;
}

int main()
{
int p=fact();
cout<<p;
 return 0;
}
 

Function with arguments and no return value

#include<iostream>
using namespace std;
void fact(int x)
{
long int f=1;
for(int i=1;i<=x;i++)
f=f*i;
cout<<"factorial of "<<x<<"=" <<f;
}

int main()
{    int n;
    cout<<"enter a no";
    cin>>n;
    fact(n);
    return 0;
}

Function with arguments and a return value

#include<iostream>
using namespace std;
int fact(int x)
{
long int f=1;
for(int i=1;i<=x;i++)
f=f*i;
return f;
}

int main()
{    int n;
    cout<<"enter a no ";
    cin>>n;
    int p=fact(n);
    cout<<"factorial of "<<n<<" "<<p;
    return 0;
}

structure in c++

In C++, the structure is a user-defined data type. When you want to use different  data types in a single unit then structure is used. It is declared by the key word struct.
A structure in c++ is different form the Class data type. In class all the variables are private by default while in the structure all the variables are always public. There is no concept of private or public in a structure data type.

//program to declare and initialize a structure.

struct student
{
  int roll,
 float marks;
};

int main()
 {
  struct student e1;
  e1.roll = 5;
  e1.marks = 39;
 
  //accessing the values thru the variables

  cout<< "roll: " << e1.name <<endl;
  cout<< "marks : " << e1.age <<endl;
 }


//program to declare a structure and input the values thru variables.
 
struct student
{
  int roll;
  float marks;
};

int main()
 {
 struct student e;
cout<<" enter your roll no:";
cin>>e.roll;
cout<<" enter your marks:";
cin e.marks;

 //diplay the result
cout<<"roll="<<e.roll<<endl;
cout<<"marks="<<endl;
}
 
//program to declare an array of structure of 5 size.
 
struct student
{
  int roll;
  float marks;
};

int main()
 {
 struct student e[5];

 for(int i=0;i<5;i++)
{
cout<<" enter your roll no:";
cin>>e[i].roll;
cout<<" enter your marks:";
cin e[i].marks;
}

 //diplay the result

 for(int i=0;i<5;i++)
{
cout<<" your roll no: ";
cout<<e[i].roll;
cout<<" your marks: ";
cout<<e[i].marks;
cout<<endl;
}

}
// In above programs kindly include header files.






List of C++ Compilers

 A compiler is a software that translates a source program written in some high-level programming language (such as C,C++ etc) into machine code.

List of Off-line Compilers::
 
1.  Turbo C++
2.  Eclipse IDE
3.  NetBeans IDE
4.  Borland C++
5.  DevC++
6.  CodeLite
7.  Codeblocks
8.  Notepad++
9.  Microsoft Visual C++
10. MinGW
 
serial no 1, 4 and 5 consumes very less memory after installation and very less hard disk space. 

List of on line Compilers::>

Codepad
OnlineGDB
w3schools.com 
tutorialspoint 
 
You must be online while using the on-line compilers ie. your net connection should be on always while executing the source code.