คำอธิบายโปรแกรม
กำลังสองของตัวเลขคือจำนวนนั้นคูณด้วยตัวมันเอง
จำนวนกำลังสองหรือกำลังสองสมบูรณ์คือจำนวนเต็มที่เป็นกำลังสองของจำนวนเต็ม
กำลังสองสมบูรณ์คือกำลังสองของจำนวนเต็ม
1, 4, 9, 16, 25, 36, 49, 64, 81, 100
ต่อไปนี้คือรากที่สองของกำลังสองสมบูรณ์ทั้งหมดตั้งแต่ 1 ถึง 100
√1 = 1 since 12 = 1 √4 = 2 since 22 = 4 √9 = 3 since 32 = 9 √16 = 4 since 42 = 16 √25 = 5 since 52 = 25 √36 = 6 since 62 = 36 √49 = 7 since 72 = 49 √64 = 8 since 82 = 64 √81 = 9 since 92 = 81 √100 = 10 since 102 = 100
กำลังสองที่ไม่สมบูรณ์แบบคือทุกจำนวนที่ไม่ได้เป็นผลมาจากการยกกำลังสองจำนวนเต็มด้วยตัวมันเอง
ตัวเลขด้านล่างเป็นตัวเลขกำลังสองไม่สมบูรณ์
2,3,5,6,7,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24,26 etc…
อัลกอริทึม
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.
ตัวอย่าง
/* 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("\n");
for(i = 1;times<number;i++,times++){
x = sqrt(i);
if(i!=x*x){
printf("%d\t", i);
}
}
getch();
return 0;
} ผลลัพธ์
