Home > Backend Development > C++ > body text

Print non-square numbers in C language

WBOY
Release: 2023-08-26 23:09:04
forward
1343 people have browsed it

Program Description

The square of a number is the number multiplied by itself.

A square number or perfect square is an integer that is the square of an integer;

A perfect square number is the square of an integer.

1, 4, 9, 16, 25, 36, 49, 64, 81, 100
Copy after login

Here are the square roots of all perfect square numbers from 1 to 100.

&radic;1 = 1 since 1<sup>2 </sup>= 1
&radic;4 = 2 since 2<sup>2 </sup>= 4
&radic;9 = 3 since 3<sup>2 </sup>= 9
&radic;16 = 4 since 4<sup>2 </sup>= 16
&radic;25 = 5 since 5<sup>2 </sup>= 25
&radic;36 = 6 since 6<sup>2 </sup>= 36
&radic;49 = 7 since 7<sup>2 </sup>= 49
&radic;64 = 8 since 8<sup>2 </sup>= 64
&radic;81 = 9 since 9<sup>2 </sup>= 81
&radic;100 = 10 since 10<sup>2 </sup>= 100
Copy after login

A non-perfect square is every number that is not the result of squaring an integer with itself.

The below numbers are non-perfect square numbers

2,3,5,6,7,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24,26 etc&hellip;
Copy after login

Algorithm The Chinese translation of

Check all numbers from 1 to the user specified number.
Check if it is perfect square or not.
If not a perfect square, print the Non Perfect Square Number.
Copy after login

Example

is:

Example

/* Program to print non square numbers */
#include <stdio.h>
#include <math.h>
int main() {
   int number,i,x;
   int times = 0;
   clrscr();
   printf("Print the Non Square Numbers till:");
   scanf("%d", &number);
   printf("The Non Squre Numbers are:");
   printf("</p><p>");
   for(i = 1;times<number;i++,times++){
      x = sqrt(i);
      if(i!=x*x){
         printf("%d\t", i);
      }
   }
   getch();
   return 0;
}
Copy after login

Output

Print non-square numbers in C language

The above is the detailed content of Print non-square numbers in C language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template