Please write out your logic flow, as well as the functions for 1) multiply2Digit
ID: 3886374 • Letter: P
Question
Please write out your logic flow, as well as the functions for 1) multiply2Digit and 2) giveAdvice
You should NOT use arrays, pointers, strings.
Explanation / Answer
#include <stdio.h>
int multiply2digit(int num){
int rem,n'=1;
while(1){
while(num!=0){ //Loop to find individual digit of number num and multiply them
rem=num%10;
num=num/10;
n'=n'*rem;
}
if(n'/10==0) //check whether ir is single digit or not
break;
else //repeat it until single digit n' is not found
num=n';
return n';
}
}
void printAdvice(int num,int sign){
if(sign==1){ //Check condition for positive values
if(num==0||num==3||num==7||num==9)
printf("You should protect life");
else if(num==2||num==5||num==8)
printf("Share your wealth,donate generously");
else
printf("Build harmony,bring people together");
}
else if(sign==0){ //check condition for negative values
if(num==0||num==3||num==7||num==9)
printf("Speak Honestly");
else if(num==2||num==5||num==8)
printf("Praise other's success");
else
printf("Lend your hand in those who need it");
}
}
int main() {
int num,sign=0,digit; //Assume sign to be negative initially (0->negative sign, 1 ->positive sign)
printf("Enter a non-zero integer");
scanf("%d",num);
if(num>=0) //Change sign if it is positive
sign=1;
digit=multiply2digit(abs(num));
printAdvice(digit,sign);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.