1.

A number is said to be a trendy number if and only if it has 3 digits and the middle digit is divisible by 3. Examples of trendy numbers: 131, 264, 999 examples of nontrendy numbers : 123, 653, 33, 4, 1034 write a program to find whether a given number is a trendy number or not. Input format: input consists of a single integer. Output format: refer sample output for details. Sample input 1: 791 sample output 1: trendy number sample input 2: 3 c program

Answer»

am to check whether a given number is a Trendy Number or Not.Language used : C programming.Program :#include int MAIN(){    int a,b,count;    printf("Enter a number : ");    scanf("%d",&a);    //finding the number of numbers present in the number in variable 'a'.    while (a != 0)    {        a /= 10;        ++count;    }    if(count!=3)    {        printf("%d is NOT a trendy number", a);    }    else    {        b = (a / 10) % 10 ;   // b has the middle number now.        if(b%3==0)        {            printf("%d is a trendy number", a);        }        else        {         printf("%d is NOT a trendy number", a);          }    }    RETURN 0;}Inputs and outputs :Input 1 :123Output 1 :123 is NOT a trendy numberInput 2 :261Output 2 :261 is a trendy numberInput 3 :79725Output 3 :79725 is NOT a trendy numberExplanation :Declare the necessary variables. You can declare them as the code progresses further, too.Ask user to input an integer which we should find whether it is a tendy number or not.Once inputted, check the count of the number of digits present in the number.If the count is not equal to 3, print a statement stating that the given number is not a trendy ONE.Else, TAKE out the middle value of the three digit number and check whether it LEAVES a remainder 0 on dividing with 3.If yes, print that it is a trendy number, else print that it is not a trendy one. That's it!Learn more :1) Palindrome program in C.brainly.in/question/23725802) Define programming in C++brainly.in/question/17432354



Discussion

No Comment Found