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";
}
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