Price of a Product ID:6747
The program must accept two integers representing a coupon code C and a price of a product P as the input. If the count of the digits of C is even, then 20% discount is applied. If the count of the digits of C is odd, then 30% discount is applied. If all the digits of C are equal, then 50% discount is applied. If more than one conditions are satisfied, then 50% discount is applied. The program must print the price of the product as the output.
Example Input/Output 1:
Input:
1213 100
Output:
80
Example Input/Output 2:
Input:
12353 100
Output:
70
Example Input/Output 3:
Input:
111 100
Output:
50
PROGRAM IN C:
#include<stdio.h>
#include<stdlib.h>
int cd(int d)
{int count=0;
int f=d,g=d;
int r[1000];
int i=0;
while(f!=0)
{g=f%10;
f/=10;
count++;
r[i]=g;
i++;
}
int w=r[0],fl=0;
for(int j=0;j<i;j++)
{
if(r[j]!=w)
fl=1;
}
if(fl==0)
return -2;
return count;
}
int main()
{
int a,b;
scanf("%d %d",&a,&b);
float p;
int z=cd(a);
if(z==-2)
p=0.50;
else if(z%2==0 )
p=0.2;
else if(z%2!=0)
p=0.3;
printf("%.0f",b-(p*b));
}
Comments
Post a Comment