Introduction to Programming (Practical) - Functions, Exercises of Computer Science

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

2018/2019

Uploaded on 12/08/2019

diksha-prabhukhorjuvenkar
diksha-prabhukhorjuvenkar 🇮🇳

1 document

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
DEPARTMENT OF COMPUTER SCIENCE
ACADEMIC YEAR: 2019-2020
Programme : BSc
Class : FYBsc
Course Name: Introduction to Programming (Practical)
Semester: I
Name: Manasi Athalye
Roll no. : SU190190
Class: FYBSc Computer Science
1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Introduction to Programming (Practical) - Functions and more Exercises Computer Science in PDF only on Docsity!

DEPARTMENT OF COMPUTER SCIENCE

ACADEMIC YEAR: 2019-

Programme : BSc Class : FYBsc Course Name: Introduction to Programming (Practical) Semester: I Name: Manasi Athalye Roll no. : SU Class: FYBSc Computer Science

INDEX

Sr. No. Date Title Page No. Signature

1 23/7/2019 Introduction to C. 3

2 30/7/2019 Conditions.

3 6/8/2019 Iterations.

4 13/8/2019 PA-

5 20/8/2019 Functions.

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: