Question #38034

write a c program of n positive integers and find how many perfect squres are their input values must be in the range 1 to 10000 in c language

Expert's answer

#include <stdio.h>
#include <conio.h>
#include <math.h>
int main() //enter point
{
    int num(0); //number of digits to input
    printf("Please enter number of digits to input:(1...1000)\n");
    scanf("%4d",&num); //get digit from keyboard
    if(num<=0||num>1000)
    {
        printf("Wrong input. Good Bye");
        getch();
        return 0;
    }
    int *pnum = new int[num]; //contains all digits
    printf("\n Please enter %d digit(s) in the range 1 to 10000:\n",num);
    for(int i=1;i<=num;i++)
    {
        printf("%d)\t",i);
        scanf("%d",pnum+i-1);
        if(*(pnum+i-1)<1||*(pnum+i-1)>10000)
        {
            printf("\t Wrong input. Try again\n");
            i--;
            fflush(stdin); //clearing input buffer
            continue;
        }
    }
    long digit(0);
    int count(0);
    for(int i=0;i<=num;i++)
    {
        digit=sqrt(*(pnum+i));
        if(digit*digit==*(pnum+i)) count++;
    }
    printf("\n\nWe have %d digit(s) with perfect squares", count);
    getch();
    return 0;
}

Answer on Question#38034 - Programming - C

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS