Program in C++ to add the given numbers (<10) using function with default arguments
#include<iostream> #include<conio.h> using namespace std; int Add(int a,int b,int c=0,int d=0,int e=0,int f=0,int g=0,int h=0,int i=0,int j=0) { return(a+b+c+d+e+f+g+h+i+j); } int main() { cout<<" Add(1,2) ="<<Add(1,2); cout<<endl<<" Add(1,2,3) ="<<Add(1,2,3); cout<<endl<<" Add(1,2,3,4) ="<<Add(1,2,3,4); cout<<endl<<" Add(1,2,3,4,5) ="<<Add(1,2,3,4,5); cout<<endl<<" Add(1,2,3,4,5,6) ="<<Add(1,2,3,4,5,6); cout<<endl<<" Add(1,2,3,4,5,6,7) ="<<Add(1,2,3,4,5,6,7); cout<<endl<<" Add(1,2,3,4,5,6,7,8) ="<<Add(1,2,3,4,5,6,7,8); cout<<endl<<" Add(1,2,3,4,5,6,7,8,9) ="<<Add(1,2,3,4,5,6,7,8,9); cout<<endl<<" Add(1,2,3,4,5,6,7,8,9,10) ="<<Add(1,2,3,4,5,6,7,8,9,10); return 0; }Output:-
0 Comments