Lab Report 5
Lab Report 5
Submitted by:
Name: Md. Abid Al Azmain Shakil
ID: 2251081143
Batch: 63(D)
Department: CSE
Submitted to:
Name: Noor Easrib Tiba
Submission Date: 06/03/2025
Department of CSE
Uttara University
Introduction
Description
Program to Calculate the Sum of the Series 1, 2, 3, ..., n: This program calculates the sum of the
first n natural numbers. It iterates through all integers from 1 to n, adding each number to a
cumulative sum. The program demonstrates how to use loops for performing repetitive
arithmetic operations and is a great way to learn about the basic concept of series summation.
Program to Calculate the Sum of Two Series 1, 3, 5, 7,..., n and 2, 4, 6, 8,..., n: This program
calculates the sum of two distinct arithmetic series: one consisting of odd numbers and the other
consisting of even numbers, both up to a given number n. The program loops through the range
and categorizes each number as either odd or even, adding them separately to maintain
separate sums. It helps understand how to manage multiple conditions within loops.
Program to Reverse the Order of an Integer Number: This program takes an integer input and
reverses the digits of the number. Using a loop, it repeatedly extracts the last digit of the number
and builds a new integer by appending each extracted digit. This demonstrates how to
manipulate the individual digits of a number, which is a common task in many real-world
applications like data formatting.
Program to Check Whether an Integer is a Palindrome: This program checks if a given integer is
a palindrome. A palindrome number is one that remains the same when its digits are reversed.
The program first reverses the number and then compares it with the original number. If they
are the same, the number is a palindrome. This helps illustrate how to work with numbers and
compare their properties.
Program to Check Whether an Integer is an Armstrong Number: An Armstrong number (or
narcissistic number) is a number that is equal to the sum of its own digits each raised to the
power of the number of digits. This program calculates the sum of the digits of a number raised
to the power of the number of digits and checks if the sum equals the original number. This task
is often used in number theory problems and provides a deeper understanding of how to
manipulate and analyze numbers in programming.
Program to Count the Number of Digits in an Integer Number: This program counts how many
digits a given integer has. By repeatedly dividing the number by 10, the program keeps track of
the number of times this operation is performed until the number becomes zero. This program
provides insight into number manipulation and helps solidify the understanding of basic
mathematical operations in programming.
Experiment No. 1
Source Code
#include<stdio.h>
int main()
{
int i = 1;
int sum = 0;
//Using loop and unary operator
while(i<=100)
{
sum = sum+i;
i++;
}
//Display result
printf("The sum of the following series is : %d", sum);
return 0;
}
Output
Experiment No. 2
Source Code
#include<stdio.h>
int main()
{
//Variable initialization
int i = 1;
int sum_odd = 0,sum_even = 0;
//Using loop and unary operator
while(i<=100)
{
if(i%2==0)
{
sum_even = sum_even + i;
}
else
{
sum_odd = sum_odd + i;
}
i++;
}
//Display result
printf("Sum of the odd numbers is : %d\n", sum_odd);
printf("Sum of the even numbers is : %d\n", sum_even);
return 0;
}
Output
Experiment No. 3
Source Code
#include<stdio.h>
int main()
{
int num, reverse = 0, remainder;
Output
Experiment No. 4
Source Code
#include <stdio.h>
int main()
{
int num, originalnum, reversednum = 0, remainder;
return 0;
}
Output
Experiment No. 5
Source Code
#include <stdio.h>
#include <math.h>
int main()
{
int num, originalnum, remainder, sum = 0, digits = 0;
return 0;
}
Output
Experiment No. 6
Source Code
#include <stdio.h>
int main()
{
int num, count = 0;
return 0;
}
Output
Conclusion
1. Sum of Sequences: We calculated the sum of natural numbers, odd numbers, and even
numbers, which reinforces our understanding of loops and arithmetic operations.
2. Reverse Operations: We learned how to reverse the digits of a number, which is an
essential task in many applications.
3. Palindrome Check: We practiced checking for palindromes, helping us understand how to
compare original and reversed versions of numbers.
4. Armstrong Numbers: We explored Armstrong numbers, which involves extracting and
raising digits to specific powers, and we saw how mathematical concepts can be
implemented in code.
5. Digit Counting: Counting the digits of a number helped us reinforce the use of loops and
integer operations in real-world problems.
What We Learned:
• Looping Constructs: Mastery of using for and while loops to solve problems such as
summing series, reversing digits, and counting digits.
• Mathematical Operations: We applied basic arithmetic and modulus operations to solve
practical problems.
• Number Theory: We explored interesting properties of numbers such as Armstrong
numbers and palindromes, which are widely used in mathematical computations.
Mistakes to Avoid:
1. Ignoring Input Validation: When taking user input, always ensure the input is valid. For
example, negative numbers might need to be handled separately for problems like digit
counting or Armstrong number checking.
2. Incorrect Logic in Palindrome or Armstrong Check: Be careful while comparing the
original number with the reversed or calculated sum in palindrome and Armstrong
checks. Small mistakes in logic can lead to incorrect results.
3. Using Incorrect Data Types: Ensure that you're using the correct data types. For example,
when calculating powers or sums for Armstrong numbers, the result can overflow if the
data type is too small.
The End