






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The practical assignments for the 'functions' topic in the 'introduction to programming' course of the bsc computer science program during the academic year 2019-2020. Students are required to write c programs to perform various tasks using functions, such as finding the square of a number, performing arithmetic operations, finding the maximum of two numbers, generating the fibonacci series, finding the sum of digits of a number, and demonstrating call by value and call by reference. Each assignment includes a problem statement, c-source code, and sample output.
Typology: Exercises
1 / 11
This page cannot be seen from the preview
Don't miss anything!
Programme : BSc Class : FYBsc Course Name: Introduction to Programming (Practical) Semester: I Name: Manasi Athalye Roll no. : SU Class: FYBSc Computer Science
Date: 20/8/
Problem Statement: Write a C program to perform the arithmatic operations using functions. C-Source Code: #include<stdio.h> int sum(int a, int b) { return(a+b); } int diff(int a, int b) { return(a-b); } int product(int a, int b) { return(a*b); } int div(int a, int b) { return (a/b); } void main() { int n1,n2; printf("Enter the two no.s to perform operations: "); scanf("%d %d",&n1,&n2);
printf("The sum of two no.s is %d",sum(n1,n2)); printf("\nThe difference is %d",diff(n1,n2)); printf("\nThe product is %d",product(n1,n2)); printf("\nThe Quotient is %d",div(n1,n2)); } Sample Output: Experiment 3: Problem Statement: Write a C program to find maximum of two numbers using functions. C-Source Code: #include<stdio.h> int max(int num1, int num2) { return((num1>num2)?num1:num2); } void main() { int n1,n2; printf("Enter the two no.s : "); scanf("%d %d",&n1,&n2); printf("The maximum of two is %d",max(n1,n2)); }
void main() { int n; printf("Enter the no. of terms to generate fibonacci series: "); scanf("%d",&n); printf("The series is: "); fibo(n); } Sample Output: Experiment 5: Problem Statement: Write a C program to find the sum of the digits of number using functions. C-Source Code: #include<stdio.h> int sumdig(int num) { int sum=0, rem; while(num!=0) { rem=num%10; sum+=rem; num/=10;
return(sum); } void main() { int n; printf("Enter the no.: "); scanf("%d",&n); printf("The sum of digits of no. %d is %d",n,sumdig(n)); } Sample Output: Experiment 6: Problem Statement: Write a C program to show call by value using functions. C-Source Code: #include<stdio.h> void swap(int n1, int n2) { n1=n1+n2; n2=n1-n2; n1=n1-n2; printf("\nThe swapped no.s are %d and %d",n1,n2); }
printf("\nThe swapped no.s are %d and %d",n1,n2); } void main() { int num1, num2; printf("Enter the two no.s: "); scanf("%d %d",&num1,&num2); swap(&num1,&num2); printf("\nThe values of two numbers in main are %d and %d\nHence Changed",num1,num2); } Sample Output: Experiment 8: Problem Statement: Write a C program to find the sum of natural numbers using recursion. C-Source Code: #include<stdio.h> int sumofnat(int n) { if(n!=0) return(n+sumofnat(n-1)); else return(n);
void main() { int num; printf("Enter the no. of natural no.s to be added: "); scanf("%d",&num); printf("The sum of %d natural no.s is %d",num,sumofnat(num)); } Sample Output: Teacher's Signiture: