0% found this document useful (0 votes)
28 views10 pages

RUET Lab Report: Function Experiments

The document contains a lab report on experiments conducted to learn about functions in C programming. It includes four experiments: 1) A function to convert a lowercase letter to uppercase. 2) A function to check if a number is prime. 3) A function to calculate the sum of three numbers. 4) A function to find the greatest common divisor of two numbers. For each experiment, it provides the theory, methodology, code, output and conclusion. The report demonstrates how to define and use functions to perform tasks in C programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views10 pages

RUET Lab Report: Function Experiments

The document contains a lab report on experiments conducted to learn about functions in C programming. It includes four experiments: 1) A function to convert a lowercase letter to uppercase. 2) A function to check if a number is prime. 3) A function to calculate the sum of three numbers. 4) A function to find the greatest common divisor of two numbers. For each experiment, it provides the theory, methodology, code, output and conclusion. The report demonstrates how to define and use functions to perform tasks in C programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Heaven’s Light is Our Guide

Rajshahi University of Engineering & Technology

Course Code: ECE 1104


Name: Computer Programming Sessional
Lab Report 05
Name of the Experiment:
5.1 Conversion of a small letter to a capital letter using a function
5.2 Find out prime number using a function.
5.3 Summation of three numbers using a function.
5.4 Find out GCD of two numbers using a function.

Date of the Experiment: 03-11-2020


Date of Submission: 10-11-2020

Submitted to:
Submitted By:
Rakib Hassan.
A . K. M. Nasir Hasan Ashik
Lecturer, Roll: 1910042

Dept. of ECE, RUET Year: 1st year (Odd)


Experiment No: 5.1
Name of the Experiment:
Conversion of a small letter to a capital letter using a function.

Theory:
A function is a group of statements that together performs a task. A function definition in c
programming consist of a function header and a function body. Here are all the parts of
function-
 Return type.
 Function name.
 Parameters.
 Function body.

Methodology:
Variable are declared in the main function. A function is created to make the conversion of a
small letter to a capital letter before the main() function. Taking a character form the user the
created function is called to convert and print it.

Code:
#include<stdio.h>

int letters (char l)


{
char n ;
n = l-32;
return (n);
}

int main()
{
char c ;
scanf("%c", &c);
printf("%c\n", letters(c));
return 0;
}
Output:

Conclusion:
The code was executed successfully and no errors were found.
Experiment No: 5.2

Name of the Experiment:


Find out prime number using a function.

Theory:
A function is a group of statements that together performs a task. A function definition in c
programming consist of a function header and a function body. Here are all the parts of
function-
 Return type.
 Function name.
 Parameters.
 Function body.
A number that is divisible only by itself and 1 is called prime number.

Methodology:
Variable are declared in the main function. A function is created to find out the prime number
before the main() function. Taking an integer form the user the created function is called to find
out that the number is prime or not and print it.

Code:
#include<stdio.h>
#include<math.h>

int prime(int n)
{
int x ;
for(int i =2 ; i<=sqrt(n);i++){
if(n%i == 0){
return x = 0;
break;
}

}
return x=1;
}

int main()
{
int m ;
while(scanf("%d", &m))
{
int x = prime(m);
if(x == 0){
printf("not prime\n");
}
else{
printf("prime\n");
}

}
}

Output:
Conclusion:
The code was executed successfully and no errors were found.
Experiment No: 5.3
Name of the Experiment:
Summation of three numbers using a function.

Theory:
A function is a group of statements that together performs a task. A function definition in c
programming consist of a function header and a function body. Here are all the parts of
function-
 Return type.
 Function name.
 Parameters.
 Function body.

Methodology:
Variable are declared in the main function. A function is created to find out the summation
before the main() function. Taking 3 integer form the user the created function is called to find
out the summation and print it.

Code:
#include<stdio.h>

int sum(int a,int b, int c)


{
int s = a+b+c;
return s ;
}

int main()
{
int p,q,r;
scanf("%d %d %d", &p,&q,&r) ;
printf("sum = %d\n",sum(p,q,r) );
}

Output:

Conclusion:
The code was executed successfully and no errors were found.
Experiment No: 5.4
Name of the Experiment:
Find out GCD of two numbers using a function.

Theory:
A function is a group of statements that together performs a task. A function definition in c
programming consist of a function header and a function body. Here are all the parts of
function-
 Return type.
 Function name.
 Parameters.
 Function body.
The greatest common divisor(GCD), also called the greatest common factor, of two number is
the largest number that divides them both.

Methodology:
Variable are declared in the main function. A function is created to find out GCD before the
main() function. Taking two integer form the user the created function is called to find out the
GCD and print it.

Code:
#include<stdio.h>

int gcd(int a, int b)


{
if(b!= 0){
return gcd(b,a%b);
}
else{
return a;
}
}

int main()
{
int m , n;

scanf("%d%d", &m, &n);


printf("Gcd = %d\n", gcd(m,n));
}

Output:

Conclusion:
The code was executed successfully and no errors were found.

You might also like