Posts

Showing posts with the label C Programs

Program to find perfect square between 1 and 500 in C

Problem Statement: Write a program to find a perfect square between 1 and 500 in C using while loop. HINT: A number is said to be perfect square if multiples of a number are same. eg., 16 is perfect square because it's multiples are 4 * 4.   #include <stdio.h> #include <math.h> int main() {     int start=1;    while(start<500){ //change 500 to any n        if (sqrt(start) == (int)sqrt(start)) {            printf("%d ",start);        }        start++;    }     return 0; } Run above code now Here we are going to solve using sqrt() in <math.h>. sqrt() returns double value. (int)sqrt() returns int value. If both float and int are same, then it is a perfect square. [i.e., 4.0 == 4] and print that number. You can also incre...