Homework 05
Homework 05
5th Homework
CSE115L
Farhan Mahtab
CSE115.3
2422232642
Question 1: Find the sum of the following series using
user-defined function: 1/1! + 2/2! + 3/3! + ...... +N/N!
Code:
Result:
Question 2: Write a C code using functions that takes
two integers: a and b as inputs and returns the value of
ab.
Code:
#include <stdio.h>
return a * b;
int main()
int a, b;
scanf("%d", &a);
scanf("%d", &b);
return 0;
}
Result:
Question 3: Compute the sum of the following geometric
progression using a function with 2 parameters r and n:
1 + r + r^2 + ... + r^n
Code:
#include <stdio.h>
double sum = 0;
double term = 1;
int i;
sum += term;
term *= r;
return sum;
int main()
int r, n;
double result;
scanf("%d", &r);
printf("Enter the exponent (n): ");
scanf("%d", &n);
return 0;
Result:
Question 4: Write a C program that reads an integer and
returns the reverse of that number using function.
Code:
#include <stdio.h>
while (num != 0)
num /= 10;
return reversed;
int main()
scanf("%d", &number);
reversed = reverseNumber(number);
printf("\nThe reverse of %d is: %d\n", number, reversed);
return 0;
Result:
Question 5: Write a C program using function that reads a floating point number n
and an integer d and then prints the rounded value of n up to d decimal places.
Code:
#include <stdio.h>
#include <math.h>
double factor;
int main()
double n, rounded;
int d;
scanf("%lf", &n);
scanf("%d", &d);
Result: