Probelm:
To find the perfect square no for given nu , example give no 160 then it should print near perfect square is 169
Solution:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,j,n,avg1;
float avg2;
clrscr();
printf("enter the no");
scanf("%d",&n);
i=n;
j=n;
while(1)
{
i++;
j--;
avg1=sqrt(i);
avg2=sqrt(i);
if(avg1==avg2)
{
printf("the near perfect square is %d ",i);
break;
}
avg1=sqrt(j);
avg2=sqrt(j);
if(avg1==avg2)
{
printf("the near perfect square is %d ",j);
break;
}
}
getch();
}
Output:
To find the perfect square no for given nu , example give no 160 then it should print near perfect square is 169
Solution:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,j,n,avg1;
float avg2;
clrscr();
printf("enter the no");
scanf("%d",&n);
i=n;
j=n;
while(1)
{
i++;
j--;
avg1=sqrt(i);
avg2=sqrt(i);
if(avg1==avg2)
{
printf("the near perfect square is %d ",i);
break;
}
avg1=sqrt(j);
avg2=sqrt(j);
if(avg1==avg2)
{
printf("the near perfect square is %d ",j);
break;
}
}
getch();
}
Output:
If anyone is here can you explain the logic..
ReplyDelete