А
company Selenia 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 customerlD numbered from 0 to N-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.
31
4 #include
5
6 using namespa
7
int main()
9-
10
char name
11
cin >> nam
12
cout << "H
13 return 0;
14 }
15 */
16
17 // Warning: Pri
18
19 #include
20
21
using namespace
22
23
int main()
24 -
Write an algorithm to help Andy find the
number of customers that will be given
discounts
Answers
Answer:
The code for above problem in c and python language is
Explanation:
1. C language
#include<stdio.h>
#include<math.h>
int PerfectSquareBill(int n)
{
int integerValue;
float floatVaue;
floatVaue=sqrt((double)n);
integerValue=floatVaue;
if(integerValue==floatVaue)
return 1;
else
return 0;
}
int main(){
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
}
2. Python language
#import math
def perfectSquare(x):
root = math.sqrt(x)
if int(root + 0.5) ** 2 == x:
return 1
else:
return 0
uniqueCustomerId = [36, 16, 54, 81, 48, 49]
count = 0
print("Input")
print("Unique customer id numbered from 0 to n-1.")
print(uniqueCustomerId)
print("Total number of customers are: "+str(len(uniqueCustomerId)))
for uniqueId in uniqueCustomerId:
if perfectSquare(uniqueId) == 1:
count += 1
print("Output")
#SPJ2