सम वर्ग संख्याएँ होती हैं - 2 2 , 4 2 , 6 2 , 8 2 ,………
=4, 16, 36, 64, 100, ………
एल्गोरिदम
START Step 1: declare two variables a and n Step 2: read number n at runtime Step 3: use for loop to print square numbers For a=2; a*a<=n;a+=2 until the condition satisfy loop will continue and Print a*a STOP
कार्यक्रम 1
#include<stdio.h> int main(){ int a,n; printf("enter a number for n:"); scanf("%d",&n); for(a=2;a*a<=n;a+=2) //print even squares that are present in between 1 and n{ printf("%d\n",a*a); } return 0; }
आउटपुट
enter a number for n:200 4 16 36 64 100 144 196
कार्यक्रम 2
1 से n के बीच सम घनों को खोजने का कार्यक्रम निम्नलिखित है -
#include<stdio.h> int main(){ int a,n; printf("enter a number for n:"); scanf("%d",&n); for(a=2;a*a*a<=n;a+=2){ printf("%d\n",a*a*a); } return 0; }
आउटपुट
enter a number for n:300 8 64 216