Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Office Hours: Monday 4:45-6:15 &Tuesday; 4:00-5:30 Course Website: https://d2l.d

ID: 3589905 • Letter: O

Question


Office Hours: Monday 4:45-6:15 &Tuesday; 4:00-5:30 Course Website: https://d2l.depaul.edu/ Practice Problems 1. Write a program that takes as input the ternary representation of a positive integer n and outputs its decimal representation. 2. Two positive integers are called Amicable (or friendly) if each equals to the sum of the aliquot divisors of the other (aliquot divisors means all the divisors excluding the number itself). For example, 220 and 284 are amicable because the aliquot divisors of 220 are 1, 2, 4, 5, 10 11, 20, 22, 44, 55 and 110, which sum to 284, and the aliquot divisors of 284 are 1, 2, 4, 71 and 142, which sum to 220. Write a program that takes as input two positive integers and checks if their amicable or not. 3. Write a program that takes as input a positive integer n and generates the following shape.

Explanation / Answer

1. For ternary to decimal:

#include <stdio.h>
#include <math.h>

int main()
{
int sum=0,i=0,n,x,y;
printf("enter value of ternary");
scanf("%d",&n);
while(n>0)
{
x=n%10;   
y=x*(pow(3,i));
  sum=sum+y;
i++;
n=n/10;
}
printf(" decimal value is %d",sum);
return 0;
}

output:

enter value of ternary

123

decimal value is 18

2.Amicable or not:

#include <stdio.h>

int main()
{
int a,b,c=0,d=0,max,i=1;
printf("enter value of first number");
scanf("%d",&a);
printf(" enter value of second number");
scanf("%d",&b);

if(a>b)
max=a;
else max=b;
max=max/2;
  
while(i<=max){
  
if((a%i)==0){c=c+i;}
  
if((b%i)==0){d=d+i;}
i++;
}
printf(" ............ ");
if((a==d)&&(b==c))
{
printf(" Amicable ");
}
  
else
{printf("Not amicable");
}
return 0;
}

output:

enter value of first number

220

enter value of second number

284

............................

Amicable

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote