Question

Please type the answer for i can copy it. Thank you very much. -Question Describe decision...

Please type the answer for i can copy it. Thank you very much.

-Question

Describe decision processing control structures. Provide a unique scenario that requires the use of decision processing to solve a business problem.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*

Author - Ripul Vohra

Do give me thumbs up.

*/

Decision Processing Control Structures are the structures that define control the flow of a program. The decision is made on the basis of some condition and this condition is responsible for controlling the flow of the progrom. There are various types of control structures : Branch, Loop and Jump.

A. The branch instruction contains :

1. if, if else - else cannot occur without if. They occur with a pair. if can occur without else.

Example program to check if number is less than or greater than or equal to 5 .

#include<stdio.h>

int main(){

int a; scanf("%d",&a);

if(a>5) printf("a is greater than 5");

else if(a==5) printf("a is equal to 5");

else printf(a is smaller than 5");

return 0;

}

2. switch - switch is used to send the control of program to a particular according to the parameter passing in it .

Example program to check if number is equal to 5 or not.

#include<stdio.h>

int main(){

int a; scanf("%d",&a);

switch(a)

{

case 5 : a is equal to 5; break;

default : a is not equal to 5;

}

return 0;

}

B. Loop structures : These are required if some piece of code needs to repeated.

1. for loop : for loop has three parts - initialistion, condition check and increment/decrement.

Example program to print numbers from 1 to 100.

#include<stdio.h>

int main(){

for(int i=1;i<=100;i++)

{

printf("%d ",i);

}

return 0;

}

2. while loop - while loop contains a condition check. All the instructions inside the loop will keep on executing until the condition is true.As soon as the conditions returns false, program exits from loop.

Example Program to print number from 1 to 100 :

#include<stdio.h>

int main(){

int i=1;

while(i<=100)

{

printf("%d ",i);

i++;

}

return 0;

}

3. do-while loop - do while loop is similar to while loop except the do part which will always be executed irrespective of condition being true or false.

Example Problem

#include<stdio.h>

int main(){

int i=0;

do

{

printf("Hello\n");

}while(i<0)

return 0;

}

Output will be - Hello

C. Jumping Instructions : These are required to jump to a particular piece of code in the whole program. These include:

1. break - break command is used to come out of looping instructions.

Example program to print all the numbers from 1 to 100

#include<stdio.h>

int main(){

int i=1;

while(true)

{

if(i>100) break;

printf("%d ",i);

i++;

}

return 0;

}

2. continue - continue is used to skip a particular piece of code that is under the continue condition and sends the control flow back to loop parameters.

Example Program to print numbers from 1 to 100 except 37

#include<stdio.h>

int main(){

for(int i=1;i<=100;i++)

{

if(i==37) continue;

printf("%d ",i);

}

return 0;

}

Use of Control Structues in Business Problem :

Business Problem : Suppose, a company Amnesia has launched a hair oil and is selling this hair oil in various parts of India. Now, they have recieved a profit sheet in form of an array. Array tells them profit numbers in various cities. Now,according to them, if profit earned by product is more than 30%,then it will be continued for that particular city. Otherwise,they are gonna stop selling their product in that city. And in some cities,profit will be more than 50%. So they are gonna increase their sales for those cities. Now,they want you to write a program to tell number of cities in which sales needs to stopped and number of cities for which sales need to be increased.

Input Data of 20 cities -

12,89,63,74,34,56,32,45,65,11,54,34,67,23,27,76,24,53,77,61

Use of control statements in the program -

#include <stdio.h>
int main()
{
int sales[20]={12,89,63,74,34,56,32,45,65,11,54,34,67,23,27,76,24,53,77,61};
int cities_stop=0;
int cities_increase=0;
for(int i=0;i<20;i++)
{
if(sales[i]<30) cities_stop++;
else if(sales[i]<=50) continue;
else cities_increase++;
}
printf("No of Cities for which sales need to be stopped = %d\n",cities_stop);
printf("No of Cities for which sales need to be increased = %d",cities_increase);
}

OUTPUT-

No of Cities for which sales need to be stopped = 5
No of Cities for which sales need to be increased = 11

So, for loop(looping), if else(branching ) and continue(jumping) all of these control stuctures were used in this business problem.

Add a comment
Know the answer?
Add Answer to:
Please type the answer for i can copy it. Thank you very much. -Question Describe decision...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT