首頁 > 後端開發 > C++ > 主體

列印C語言中的非平方數

WBOY
發布: 2023-08-26 23:09:04
轉載
1318 人瀏覽過

程式描述

一個數的平方是該數乘以自身。

一個平方數或完全平方是一個整數,它是一個整數的平方;

完全平方數是整數的平方。

1, 4, 9, 16, 25, 36, 49, 64, 81, 100
登入後複製

這裡是從1到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
登入後複製

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 number##

2,3,5,6,7,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24,26 etc&hellip;
登入後複製

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.
登入後複製

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;
}
登入後複製

輸出

列印C語言中的非平方數

以上是列印C語言中的非平方數的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:tutorialspoint.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!