1. Create a program to test for a palindromes. a. Must take command line argumen
ID: 674759 • Letter: 1
Question
1. Create a program to test for a palindromes.
a. Must take command line arguments.
b. cannot use string.h
c. Sample output Is a Palindrome or Is Not a Palindrome
2. Create a that computes the power and any give number.
a. The prototype is as follows double(double, double);
b. Cannot use include math.h
c. Must use command line arguments. argv[1] = number, argv[2] = power
3. Create a program that prints a string. a. Cannot use printf with a "%s"
b. Must print every other character of the word in reverse order. c. example... EET3150 output is 01TE
d. Be sure to handle both even and odd lengths. e.. no string.h, scanf
f. the word to print will come from the command line arguments argv[1].
Explanation / Answer
#include <stdio.h>
int palin(char l[]){
int n = strlen(l);
for (int i = 0; i < n; i++){
if (l[i] != l[n-i-1]){
// 0 if not a palindrome
return 0;
}
}
// 1 if palindrome
return 1;
}
int main(int argc, char *argv[]){
char l[] = argv[1];
cout << palin(l) << endl;
return 0;
}
2)
#include <stdio.h>
double power(double n,double x){
double res = 1.0;
while (x > 0){
res = res * n;
x = x - 1;
}
return res;
}
int main(int argc, char *argv[]){
double number, power;
sscanf(argv[1],"%lf",&number);
sscanf(argv[2],"%lf",&power);
cout << pow(number,power) << endl;
return 0;
}
3)
#include <stdio.h>
int main(int argc, char *argv[]){
char l[] = argv[1];
int n = strlen(l);
for (int i = n-1; i >= 0; i -= 2){
printf("%c",l[i]);
}
printf(" ");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.