The algorithm written in C programming language
#include<stdio.h>
#include<math.h>
/*function to check if a customer has bill amount that is a perfect square */
int PerfectSquareBill(int n)
{
int integerValue;
float floatVaue;
floatVaue=sqrt((double)n);
integerValue=floatVaue;
if(integerValue==floatVaue)
return 1;
else
return 0;
}
int main(){
//Bill amounts for nine customers taken to test the algorithm
int CustomerBillAmounts[9] = {36, 100, 40, 18, 16, 54, 81, 48, 49};
int i, c = 0;
for(i=0; i<9; i++){
if(PerfectSquareBill(CustomerBillAmounts[i])== 1){
c +=1;
}
}
printf("%d", c); //Displaying the number of customers with perfect squares that will be given the discounts
}
Comments
Leave a comment