Pages

Friday 18 March 2011

PROGRAM TO CALCULATE SQUARE USING FUNCTION

DESCRIPTION-:This program calculate the square of 'n' numbers with the help of function.In this the function call is place under the for loop as we want to calculate the square of 'n' numbers not only one number and function definition returns the square of numbers.
FOR EXAMPLE-: If we enter the value of n-------
                                         3
 Then program generate output as---------------
                          i=0        square=0                       
                          i=1        square=1
                          i=2        square=4
                          i=3        square=9

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void square(int);
void main()
{
clrscr();
int i,n;
cout<<"enter a value for n";
cin>>n;
for(i=0;i<=n;i++)
{
square(i);
getch();
}
}
void square(int x)
{
int y;
y=x*x;
cout<<"i="<<x<<"square="<<y<<"\n";
}

0 comments:

Post a Comment

 
Copyright (c) 2010 Concepts Of C++. Design by WPThemes Expert

Blogger Templates and RegistryBooster.