Sign in to follow this  
Cornel Iulian

[C] Patrat perfect

1 post in this topic

Cerinta: Pentru un numar intreg, pozitiv 'a', sa se determine daca acesta este sau nu patrat perfect.

# include <stdio.h>
# include <stdlib.h>
# include <math.h>
int main()
{
	int a,n;
	printf("Introduceti un numar intreg: \n");
	if(scanf("%d",&a)!=1||a<=0)
	{
		printf("Date eronate.");
		exit(1);
	}
	n=sqrt(a);
	if(n*n==a)
		printf("%d este patrat perfect.\n",a);
	else
		printf ("%d nu este patrat perfect.\n",a);

	return 0;
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this