0% found this document useful (0 votes)
16 views

Assignment On Lab Experiment 07

The document is a lab report submitted by student Ashiqur Rahaman for their Structured Programming Lab course. The lab involved solving various math problems using functions, including problems on odd/even numbers, perfect numbers, binary conversion, and calculators. The student provided code solutions and output for 3 questions - determining if a number is odd or even, finding all perfect numbers between two limits, and identifying strong numbers between limits. In their analysis, the student said learning new functions helped them solve real-life inspired problems and will benefit their upcoming projects.

Uploaded by

Ashiqur Rahaman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Assignment On Lab Experiment 07

The document is a lab report submitted by student Ashiqur Rahaman for their Structured Programming Lab course. The lab involved solving various math problems using functions, including problems on odd/even numbers, perfect numbers, binary conversion, and calculators. The student provided code solutions and output for 3 questions - determining if a number is odd or even, finding all perfect numbers between two limits, and identifying strong numbers between limits. In their analysis, the student said learning new functions helped them solve real-life inspired problems and will benefit their upcoming projects.

Uploaded by

Ashiqur Rahaman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Green University of Bangladesh

Department of Computer Science and Engineering(CSE)


Faculty of Sciences and Engineering
Semester: (Spring, Year:2021), B.Sc. in CSE (Day)

LAB REPORT NO 07
Course Title: Structured Programming Lab
Course Code: 104 Section: 211-DB

Lab Experiment Name: Assignment on Lab Experiment 07

Student Details

Name ID

1. Ashiqur Rahaman 211002054

Lab Date : 26/07/2021


Submission Date : 11/08/2021
Course Teacher’s Name : Ahmed Iqbal Pritom

Lab Report Status


Marks: ………………………………… Signature:.....................
Comments:.............................................. Date:..............................
Assignment on Lab Experiment 07
In this lab experiment, we have solved various problems from calculator making,
to perfect numbers and strong numbers also many more.

Objectives/Aim
The main objective was to solve math problems.

P.T.O
(Section 6)
Answer to question no. 1

Code:
#include <stdio.h>
char* odd_even(int i);

int main()
{
int num;
printf("Enter an integer number : ");
scanf("%d", &num);

printf("Result : %s",odd_even(num));
return 0;
}
char* odd_even(int num)
{
if (num%2 == 0){
return "YOUR NUMBER IS EVEN NUMBER";
}else{
return "YOUR NUMBER IS ODD NUMBER";
}
}
Output:
Answer to question no. 2

Code:
#include <stdio.h>
int isPerfect(int num);
void printPerfect(int starting, int end);
int main()
{
int starting, end;
printf("Enter lower the limit to print perfect numbers: ");
scanf("%d", &starting);
printf("Enter the upper limit to print perfect numbers: ");
scanf("%d", &end);

printf("All perfect numbers between %d to %d are: \n", starting, end);


printPerfect(starting, end);

return 0;
}
int isPerfect(int num)
{
int i, sum;
sum = 0;
for(i=1; i<num; i++)
{
if(num % i == 0)
{
sum += i;
}
}
if(sum == num)
return 1;
else
return 0;
}
void printPerfect(int starting, int end)
{
while(starting <= end)
{
if(isPerfect(starting))
{
printf("%d ", starting);
}
starting++;
}
}
Output:
(Section 7)
Answer to question no. 1

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

long decToBin(long n);


int main() {
long decimal;
printf("Enter a decimal number\n");
scanf("%ld", &decimal);
printf("The Binary number of %ld is %ld", decimal, decToBin(decimal));

getch();
return 0;
}

/* Function to convert a decinal number to binary number */


long decToBin(long n) {
int remainder;
long binary = 0, i = 1;
while(n != 0) {
remainder = n%2;
n = n/2;
binary= binary + (remainder*i);
i = i*10;
}
return binary;
}
Output:

Answer to question no. 2

Code:
#include<stdio.h>
#include<stdlib.h>
void display(float n1, float n2, char ch, float result);
void add(float n1, float n2);
void subtract(float n1, float n2);
void multiply(float n1, float n2);
void divide(float n1, float n2);
void rem(float n1, float n2);
void power(float n1, float n2);

int main()
{
float n1, n2;
int ch;
do{
printf("Enter two numbers: ");
scanf("%f %f", &n1, &n2);

printf("\n*****************");
printf("\n1.Addition");
printf("\n2.Subtraction");
printf("\n3.Multiplication");
printf("\n4.Division");
printf("\n5.Remainder");
printf("\n6.Power (x^y)");
printf("\n7.Exit");
printf("\nEnter your choice: ");
scanf("%d", &ch);

switch (ch) {
case 1:
add(n1,n2);
break;
case 2:
subtract(n1,n2);
break;
case 3:
multiply(n1,n2);
break;
case 4:
divide(n1,n2);
break;
case 5:
rem(n1,n2);
break;
case 6:
power(n1,n2);
break;
case 7:
printf("Thank You.");
exit(0);
default:
printf("Invalid input.");
printf("Please enter correct input.");
}

printf("\n**********************************\n");
}while(1);

return 0;
}
void display(float n1, float n2, char ch, float result)
{
printf("%.2f %c %.2f = %.2f\n", n1, ch, n2, result);
}

void add(float n1, float n2)


{
float result = n1 + n2;
display(n1, n2, '+', result);
}
void subtract(float n1, float n2)
{
float result = n1 - n2;
display(n1, n2, '-', result);
}
void multiply(float n1, float n2)
{
float result = n1 * n2;
display(n1, n2, '*', result);
}

void divide(float n1, float n2)


{
float result = n1 / n2;
display(n1, n2, '/', result);
}

void rem(float n1, float n2)


{

int num1 = n1;


int num2 = n2;
int result = num1%num2;
printf("%d %% %d = %d\n", num1, num2, result);
}

void power(float n1, float n2)


{
if(n2<0) printf("The Second number should be +ve.");
else
{
float result=1.0;
for(int i=1; i<=n2; i++)
{
result *= n1;
}
display(n1, n2, '^', result);
}
}

Output:

Answer to question no. 03


Code:
#include <stdio.h>
long long fact(int num);
void printStrongNumbers(int start, int end);

int main()
{
int start, end;

printf("Enter the lower limit: ");


scanf("%d", &start);
printf("Enter the upper limit: ");
scanf("%d", &end);

printf("List of strong numbers between %d to %d are: \n", start, end);


printStrongNumbers(start, end);

return 0;
}
void printStrongNumbers(int start, int end)
{
long long s;
int num;

while(start != end)
{
s = 0;
num = start;
while(num != 0)
{
s += fact(num % 10);
num /= 10;
}

if(start == s)
{
printf("%d ", start);
}

start++;
}
}

long long fact(int num)


{
if(num == 0)
return 1;
else
return (num * fact(num-1));
}
Output:

ANALYSIS AND DISCUSSION


At first, we learned new functions as user-defined. Then we have solved some
problems with that. After practicing those problems we have solved extra
problems like finding odd, even numbers, calculators, strong numbers, etc. This
helped us to think and solve the problems that are essential for real life. That’s how
it will be a good fit for our upcoming projects.

Summary
It was a good thing that we learned new functions that can help us to solve real-life
problems.

You might also like