Sei sulla pagina 1di 15

Welcome to Practical class

Subject: ICT

Subject code: 275


Conducted by

Rashedul Islam
Lecturer in Computer Science
Rajuk Uttara Model College
Lab Work # 10 Date of Lab work: / /2014

Date of submission: / /2014

Name of the lab work:


Write a program in C language to calculate summation of the
series: 12+32+……………….+N2.

Theory:
To calculate summation of the series, we have to write:
Sum=sum+ixi
i=i+2
Uses of the instruments:

• Hardware :
• i. A Microcomputer/Laptop
• ii. UPS for the microcomputer
• Software :
i. Operating system-Windows XP/Windows 7/8
ii. Editor of C language: TC/Borland C/Dev C++/Code
blocks
Use :
Following procedure have to followed to perform
the above experiment in terms of using the
instruments:
1. Before starting the task, we have to check electric
connection of the computer.

2. Turn on the power switch of the computer to start it.


3. We have to check whether the above mentioned
software are installed in the computer or not.

4. To run necessary program to perform the mentioned


experiment.

5. After performing the experiment, we have to close all


the programs and shutdown the computer in proper way.
To present the results:
(a). To follow up the process:

• Following procedure have to be followed to


perform the experiment.
i. Writing algorithm
ii. Drawing flow chart
iii. To write code in any C editor
i. Algorithm of the given lab work
• Step-1:Start
• INPUT N
• Step-2: Input N
• Step-3: Set, Sum=0 And i=1
• Step-4: Sum=Sum+ixi
• Sum=0
• i=1
• Step-5: i=i+2
• Step-6: if i<=N then Go to Step-4 otherwise Go to Step-7
• Step-7: Print Sum as Result
• Sum=Sum+i
• Step-7: Stop
ii. Flow chart
iii. Code in C language
• Before writing code following procedure have
to be followed:-
• Double click on TC>Bin>Tc.exe
• Then Turbo C++ IDE window will appear.
• From this window click File>New. So following
C Editor will appear.
In this window write following code to calculate area of the
triangle:-
#include<stdio.h>
#include<conio.h>
void main()
{clrscr();
long int sum;
int i,n;
sum=0;
printf("\n\nEnter the value of N:");
scanf("%d",&n);
for(i=1;i<=n;i+=2)
sum=sum+i*i;
printf("\n\nSummationof the series1^2+3^2+5^2+.....%d^2
is=%ld",n,sum);
getch();
}
To save the file

Click on file menu


Click on Save submenu
Type series in the file name box
Click OK button. So the file will be saved
as SERIES.CPP
Explanation:
Explanation of the statements and functions used in the
program are given below:
Statement/ Description
function
#include To establish link with header file
<stdio.h> To use standard input/output function. Such as:
printf(), scanf()
<conio.h> To use function. Such as: getch()
void main() Mandatory function of every c program
clrscr() To clear the output screen
{ } Indicates start and end of every program
for Loop statement. Generally used in series.
Statement/ Description
function
long int To declare long integer type data.
printf To display anything on the screen
scanf To take input from keyboard
%d Format string of integer data
+=2 Increment operator. Value of the
variable will increment by 2.
* Arithmetic operator. It is used to
perform multiplication.
\n Newline operator
getch() To tell the program control to wait for a
single character.
Result: Open the file SERIES.CPP
Press Ctrl+F9 from the keyboard.
After providing 100 as input, following output
will be displayed as result.
Let’s have a practice……

Potrebbero piacerti anche