Answer to Question #242373 in C for Hari

Question #242373
The media company "GlobalAd" has received a
batch of advertisements from different product
brands. The batch of advertisements is a
numeric value where each digit represents the
number of advertisements the media company
has received from different product brands.
Since the company banners permit only even
numbers of advertisements to be displayed, the
media company needs to know the total
number of advertisements it will be able to
display from the given batch.
Write an algorithm to calculate the total
number of advertisements that will be
displayed from the batch.
Input
The input consists of an integer batch,
representing the batch of advertisements
Output
Print an integer representing the total number
of advertisements that will be displayed by the
media company
Constraints
0 < batchs 109​
1
Expert's answer
2021-09-26T12:27:46-0400
# include<stdio.h>
#include<stdlib.h>

/*
	The media company "GlobalAd" has received a batch of advertisements from different product brands. 
	The batch of advertisements is a numeric value where each digit represents the
	number of advertisements the media company has received from different product brands.
	Since the company banners permit only even numbers of advertisements to be displayed, the
 	media company needs to know the total number of advertisements it will be able to
 	display from the given batch. Write an algorithm to calculate the total
	number of advertisements that will be displayed from the batch.


	Input The input consists of an integer batch, representing the batch of advertisements
	Output Print an integer representing the total number  of advertisements that will be displayed by the
	media company
	Constraints		0 < batchs 109?
*/

#define MIN	0
#define MAX	109
main()
{
	int Batch_of_Advertisements=-1;
	int a, b, c;
	int No_of_Advt=0;
	
	while(Batch_of_Advertisements<MIN || Batch_of_Advertisements>MAX)
	{
		printf("\n\tEnter the Batch of Advertisements (%d to %d): ",MIN,MAX);
		scanf("%d",&Batch_of_Advertisements);
	}
	
	if(Batch_of_Advertisements <10 && Batch_of_Advertisements%2==0)
	{
		No_of_Advt=Batch_of_Advertisements;
	}
	
	if(Batch_of_Advertisements >9 && Batch_of_Advertisements<100)
	{
		a = Batch_of_Advertisements/10;
		b = Batch_of_Advertisements%10;
		if(a%2==0) No_of_Advt = No_of_Advt + a;
		if(b%2==0) No_of_Advt = No_of_Advt + b;
	}


	if(Batch_of_Advertisements >99)
	{
		a = Batch_of_Advertisements/100;
		b = (Batch_of_Advertisements%100)/10;
		c = (Batch_of_Advertisements%100)%10;
		if(a%2==0) No_of_Advt = No_of_Advt + a;
		if(b%2==0) No_of_Advt = No_of_Advt + b;
		if(c%2==0) No_of_Advt = No_of_Advt + c;
	}
	printf("\n\tNo. of advertisements = %d",No_of_Advt);
}

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
APPROVED BY CLIENTS