Computer Science, asked by monukumar2481, 11 months ago

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

Answers

Answered by poojan
1

C program to check whether a given number is a Trendy Number or Not.

Language used : C programming.

Program :

#include <stdio.h>

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 :

123

Output 1 :

123 is NOT a trendy number

Input 2 :

261

Output 2 :

261 is a trendy number

Input 3 :

79725

Output 3 :

79725 is NOT a trendy number

Explanation :

  • 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.

https://brainly.in/question/2372580

2) Define programming in C++

https://brainly.in/question/17432354

Answered by divyadivi1206
3

Answer:

Explanation:

#include<iostream>

using namespace std;

int main()

{

int n,t1,t2,t3,i;

cin>>n;

if(n>=100&&n<=999)

{

for(i=1;i<3;i++)

{

t1=n%10;

t2=n/10;

t3=t2%10;

break;

}

if(t3%3==0)

cout<<"Trendy Number";

else

cout<<"Not a Trendy Number";

}

else

cout<<"Invalid Number";

}

Similar questions