A company is planning to provide an extra discount to its customers. every order has an order I'd associated with it which is a sequence of digits.the discount is calculated as the count of the unique repeating digits in the order I'd.
#include <stdio.h>
#include <string.h>
int main()
{
char sequence[100];
char repeat[100];
int nrepeat, isrepeat, count, countall;
printf("Enter sequence of digits: ");
scanf("%[^\n]", sequence);
countall = 0;
nrepeat = 0;
for(int i = 0; i < strlen(sequence) - 1; i++)
{
count = 0;
for (int j = i; j < strlen(sequence); j++)
if (sequence[i] == sequence[j])
count += 1;
if (count > 1)
{
isrepeat = 0;
for (int k = 0; k < nrepeat; k++)
if (sequence[i] == repeat[k])
isrepeat = 1;
if (isrepeat == 0)
{
countall += count;
repeat[nrepeat] = sequence[i];
nrepeat ++;
}
}
}
printf("\nDiscont: %d\n", countall);
}
Comments
Leave a comment