0

I need help in this c code about odd perfect squares

This program should take a positive input from the user and then print all the odd perfect squares before it , and if the user enters a -ve number it should print "please enter a positive number " and take a new value, then again if user enters a -ve number the same previous thing should happen ... the second part about the -ve input is the part I can't implement correctly here , thanx in advance for any help ^^ https://code.sololearn.com/c36jt87dh3i4/?ref=app

10th Mar 2020, 3:58 PM
Manar Ahmed
Manar Ahmed - avatar
2 Antworten
+ 1
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int num; int i; printf("Enter a positive number :"); fflush(stdout); scanf("%d",&num); for(i=0; i<num; i++){ if (num<0){ printf("Please enter a positive number"); scanf("%d",&num); fflush(stdout); } else { if(i % 2 !=0 && (int)sqrt(i)==sqrt(i)) printf("%d ",i); } } return 0; }
10th Mar 2020, 5:16 PM
Prathvi
Prathvi - avatar
0
It didn't work out as desired ... Thanx a lot for your help^^
10th Mar 2020, 5:29 PM
Manar Ahmed
Manar Ahmed - avatar