Answer to Question #230207 in C for Arunn

Question #230207
a company is planning a big sale at which they will give their customers a special promotional discount. each customer that purchases a product from the company has a unique customer id numbered from 0 to n-1.

1.andy, the marketing head of the company, has selected bill amounts of the n customers for the promotional scheme. the discount will be given to the customers whose bill amounts are perfect squares. the customers may use this discount on a future purchase. write an algorithm to help andy find the number of customers that will be given discounts?
1
Expert's answer
2021-08-27T13:47:45-0400

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
}

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS