Function Parameter's



/*Function parameter 1*/
/*Function without Arguments and without return type*/





/*Write a Program to read 2 integer numbers in the Sub function
and find sum in sub function and display in sub function*/

#include <iostream>                 //header file
using namespace std;
void sum();                              //void refers that, there is NO return type.
int main()
{
  sum();
}
void sum()
{
  int a,b,s;
  cout<<"Enter two numbers";   //asking for number's
  cin>>a>>b;
  s=a+b;                                    //adding of two number's
  cout<<"sum="<<s;
}




/*Function parameter 2*/
/*Function with Arguments and without return type*/

/*Write a Program to read 2 integer numbers in the main function
and find sum in sub function and display in sub function*/

#include <iostream>                     //Header file.
using namespace std;
void sum(int,int);                          //void refers that, there is NO return type.
main()
{
  int a,b;
  cout<<"Enter two number's";    //asking for number's
  cin>>a>>b;
  sum(a,b);
}
void sum(int a,int b)
{
  int s;
  s=a+b;                                        //adding of 2 number's
  cout<<"sum="<<s;
}




/*Function parameter 3*/
/*Function without Arguments and with return type*/
 

/*Write a Program to read 2 integer numbers in the sub function
and find sum using sub function and display in main function*/


#include <iostream>                         //Header file.
using namespace std;
int sum();                                          //int refers that, there is a return type.
main()
{
  int s;
  s=sum();
  cout<<"sum="<<s;
}
int sum()
{
  int s;
  cout<<"Enter the two number's";    //asking for number's
  int a,b;
  cin>>a>>b;
  s=a+b;
  return (s);                                    //result of 's' returns to int sum();
}

No comments:

Powered by Blogger.