Assignment#5: Name: Ahmad Yar Sapid: 70112107 Section: U

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Assignment#5

Name: Ahmad yar


Sapid: 70112107
Section: u

#1
#include <iostream>
using namespace std;
int sumarray(int[], int);
int main()
{
int n=6,i, a[]={1,2,3,4,5,6};
cout<<"The sum of the elements in the array:\n";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<"is: "<<sumarray(a,n)<<endl;
system("pause");
return 0;
}
int sumarray(int a[],int n)
{
if(n==0)
return 0;
else
return a[n-1]+sumarray(a,n-1);
}

#2

#include<iostream>
using namespace std;
int recadd(int,int);
int main()
{
int x,y;
cout<<"enter x : ";
cin>>x;
cout<<"enter y :";
cin>>y;
cout<<x<<" times "<<y<<" : "<<recadd(x,y);
return 0;
}
int recadd(int x,int y)
{
if(x>=1)
{
x--;
return y+recadd(x,y);
}
else return 0;
}

You might also like