darkicewb820
BAN USER- 0of 0 votes
AnswersCan someone please help me with this? I just started C and i want to know how can i solve this, please help.
- darkicewb820 in United States
#include <stdio.h>
int main()
{
int i = 200, *p, *q;
p = &i; q = p;
*q = *q + 1;
printf("*p = %d\n", *p);
return 0;
}
Modify the program by adding another integer pointer variable r which is also an alias for variable i. Add print statements to output the dereferenced values of q and r.| Report Duplicate | Flag | PURGE
C - 0of 0 votes
AnswersWrite a recursive function:
- darkicewb820 in United States
int sum( int x, int max )
{
/* complete the code */
}
that calculates the sum of the numbers from x to max (inclusive). For example, sum (4, 7) would compute 4 + 5 + 6 + 7 and return the value 22. The function must be recursive so you are not allowed to use any conventional loop constructs| Report Duplicate | Flag | PURGE
C - 0of 0 votes
AnswersWrite a program fact.c that asks the user to enter an integer number N. The program then prints out the first N factorial numbers. Remember thatfac(1)=1, fac(n)=n*fac(n-1). You should use a function fac that is written recursively.
- darkicewb820 in United States
I cannot figure it out, please help me.| Report Duplicate | Flag | PURGE
C - 0of 0 votes
Answer#include <stdio.h>
- darkicewb820 in United States
float add (float x, float y)
{
return x + y;
}
int main()
{
float a, b, r;
char op;
do {
printf("number op number? ");
scanf(" %f %c %f", &a, &op, &b);
switch (op)
{
case '+' : r = add(a,b);
break;
case 'q' : break;
default : op='?';
}
if (op=='?')
printf("Unknown operator\n");
else if (op=='q')
printf("Bye\n");
else
printf("%f %c %f = %f\n", a, op, b, r);
}
while (op != 'q');
return 0;
}
The program behaves like a calculator asking the user to type in binary expressions (like 2.5 + 3.7) and printing out the results. If the user enters 'q' for the operator (e.g. 0 q 0) then this is taken as a signal to stop the program.
Add a new function to the program that multiplies its two arguments together and returns their product. Then modify the switch statement so that the operator '*' causes this new product function to be called. Test the program by using a mixture of '+' and '*' calculations.
Add operators for subtraction ('-') and division ('/') and test your program again.
We introduce some special operators. Write functions to implement each of these (adding one at a time and testing after each new operator is incorporated into your calculator).
Symbol Description Example
m Minimum 2.3 m 1.7 = 1.7
M Maximum 2.3 M 1.7 = 2.3| Report Duplicate | Flag | PURGE
C - 0of 0 votes
AnswerWrite a C program charcount.c that
- darkicewb820 in United States
reads in a string of no more than 255 characters from the user;
counts how many instances there are of each letter in the string; (note, for this program we ignore case so, e.g., the number of letter 'a' characters includes the total number of lower case 'a's and upper case 'A's.)
prints out the resulting count for each letter.
i.e. if the user enters "Time and Tide Wait for No Man", the program should print
a: 3 b: 0 c: 0 d: 2 e: 2 f: 1 g: 0 h: 0 i: 3 j: 0 k: 0 l: 0 m: 2
n: 3 o: 2 p: 0 q: 0 r: 1 s: 0 t: 3 u: 0 v: 0 w: 1 x: 0 y: 0 z: 0
Hint: This program is a bit trickier than the others so here is an outline of the processing required
declare a char array to store the string
declare an int array of size 26 to store the count for each letter e.g. count[0] is the number of a's, count[1] the number of b's etc.
read in the string and then process it element by element
if the element is not an alphabetic character i.e. A -Z or a - z, ignore it
otherwise, convert it to a number between 0 and 25 (i.e. a or A become 0, z or Z become 25) and update the corresponding count.| Report Duplicate | Flag | PURGE
C - 0of 0 votes
AnswersWrite a C program called string3.c that reads in a string of no more than 80 characters and then prints it back out (within double quotes) with all lower case characters changed to upper case.
- darkicewb820 in United States
Your string? C programming is fun
Modified to: "C PROGRAMMING IS FUN"| Report Duplicate | Flag | PURGE
C - 0of 0 votes
AnswerSo i have this code :
- darkicewb820 in United States
#include <stdio.h>
int main()
{
int i, j;
int * p, * q;
int ** x;
i = 100;
j = 200;
p = &i;
q = &j;
x = &p;
*p = *p + *q;
*q = **x / 2;
**x = *p + j;
printf(" i = %d\n", i);
printf("&i = %p\n", &i);
printf(" j = %d\n", j);
printf("&j = %p\n", &j);
printf(" p = %p\n", p);
printf("&p = %p\n", &p);
printf("*p = %d\n", *p);
printf(" q = %p\n", q);
printf("&q = %p\n", &q);
printf("*q = %d\n", *q);
printf(" x = %p\n", x);
printf("&x = %p\n", &x);
printf("*x = %p\n", *x);
printf("**x= %d\n", **x);
return 0;
}
I need to modify the program by adding a new variable that stores the address of x. Then use your variable to update (indirectly) the value of i and then print out the new value to demonstrate that your modification has worked.| Report Duplicate | Flag | PURGE
C - 0of 0 votes
AnswersSo i have this :
- darkicewb820 in United States
#include <stdio.h>
int main()
{
int i = 200, *p, *q;
p = &i; q = p;
*q = *q + 1;
printf("*p = %d\n", *p);
return 0;
}
I need to modify the program by adding another integer pointer variable r which is also an alias for variable i. Add print statements to output the dereferenced values of q and r.| Report Duplicate | Flag | PURGE
C