Office Hours: Monday 4:45-6:15 &Tuesday; 4:00-5:30 Course Website: https://d2l.d
ID: 3589905 • Letter: O
Question
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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.