22ADS108 Lecture : Unit-IV,V,VI_QB

7 views36 pages

Document Summary

Unit iv: write a c program to multiply 3 numbers using functions assumes that the answer is return by the function itself. #include int swap(int,int); int main() int num1,num2; printf("enter two number n1 and n2: "); scanf("%d%d",&num1,&num2); swap(num1,num2); return 0; int swap(int n1,int n2) int temp; temp=n1; n1=n2; n2=temp; printf("value of n1=%d and n2=%d",n1,n2); Recursive function: write a c program to find factorial of entered number by using recursion. #include int addnumbers(int); //function prototype int main() int num; //variable declaration printf("enter a positive integer"); scanf("%d",&num); printf("sum of series upto n terms: %d\n",addnumbers(num)); return 0; int addnumbers(int n) //recursive function definition if(n!= 0) return n+addnumbers(n-1); else return n; Unit v: write a program in c to add two 1d-arrays of size 5 and show the result in 3rd array. #include int main() int a[5],b[5],c[5],i; printf("enter 5 element of 1st array"); for(i=0;i<5;i++) scanf("%d",&a[i]); printf("enter 5 element of 2nd array"); for(i=0;i<5;i++) scanf("%d",&b[i]); printf("sum of two element of array"); for(i=0;i<5;i++)

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions