Answer to Question #301549 in C for Akhil

Question #301549

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.

1
Expert's answer
2022-02-23T06:24:02-0500
#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);
}

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