Convert in assembly language. Prog1.c #include int n= 0; int ans= -1; int main(void) { scanf("%d", &n); if (n

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Convert in assembly language. Prog1.c #include int n= 0; int ans= -1; int main(void) { scanf("%d", &n); if (n

Post by answerhappygod »

Convert in assembly language.
Prog1.c
#include <stdio.h>
int n= 0;
int ans= -1;
int main(void) {
scanf("%d", &n);
if (n == 0 || (n > 0 && n % 10 != 0)) {
ans= 0;
while (n > 0) {
ans= ans * 10 + (n % 10);
n /= 10;
}}
printf("%d\n", ans);
return 0;
}
Prog2.c
#include <stdio.h>
int number= 0;
int result= 0;
static int catalan(int n);
int main(void) {
scanf("%d", &number);
result= catalan(number);
printf("%d\n", result);
return 0;
}
static int catalan(int n) {
int ans, i;
ans= -1;
if (n >= 0) {
ans= 1;
for (i= 1; i <= n; i++)
ans= (2 * (2 * i - 1) * ans) / (i
+ 1);
}
return ans;
}
Prog3.c
#include <stdio.h>
int number= 0;
int result= 0;
static int catalan(int n);
int main(void) {
scanf("%d", &number);
result= catalan(number);
printf("%d\n", result);
return 0;
}
static int catalan(int n) {
int ans, temp;
ans= -1;
if (n == 0)
ans= 1;
else
if (n > 0) {
temp= catalan(n - 1);
ans= (2 * (2 * n - 1) * temp) /
(n + 1);
}
return ans;
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply