Sunday, 7 April 2013

Square of given number in c using array program with output

Square of numbers program

#include<stdio.h>
#include<conio.h>
void main()
{
int arr[10],i,n;
clrscr();
printf("enter the n value:");
scanf("%d",&n);
printf("\nenter the array value:\n");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("\nthe square of array values are:\n");
for(i=0;i<n;i++)
{
arr[i]=arr[i]*arr[i];
printf("%d\n",arr[i]);
}
getch();
}
 
Output:

enter the n value:5
enter the array value:

1
2
3
4
5

the square of array values are:

1
4
9
16
25

No comments:

Post a Comment