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

Enter integers a,b,c: -7 42 0 !a || !b++ && c: False (a-1 || b/2) && (c*=2): Fal

ID: 3616412 • Letter: E

Question

Enter integers a,b,c: -7 42 0
!a || !b++ && c: False
(a-1 || b/2) && (c*=2): False
(a-- || --b) && (c+=2): True
a || ! (b && --c): True

Enter integers a,b,c: 10 0 1000
!a || !b++ && c: True
(a-1 || b/2) && (c*=2): True
(a-- || --b) && (c+=2): True
a || ! (b && --c): True

Are there values of a, b, and c that would make all the results False?
Submit your answer to this question as a comment in your program.
Please explain clearly how you have arrived at this answer. Hint It
may be useful to start with the last expression and work backwards.

Problem 2
Write a C program, called digits.c, that prompts the user to enter an
integer, and then prints out its decimal digits, each one on a
separate line, starting with the least significant(rightmost)digit.
Each printed line should indicate which of the digits is being
printed. Note that the user can input either a positive or a negative
integer: the inputs n and -n, where n is an integer, should produce
exactly the same output. Here are three sample runs of this program,
assuming that the executable file is called digits.

Enter an integer: 512
Digit (1) : 2
Digit (2): 1
Digit (3): 5

Enter an integer: 0
Digit (1) : 6
Digit (2) : 1
Hint: You can use the integer division and modulo operators to parse a
positive integer into its digits. For example, n%10 produces the least
significant digit of n, while n/10 deletes this digit.

Problem#3

Write a C program, called power_of_three.c, that prompts the user to
input a positive integer , and then checks whether this integer is a
power of 3. If the input is, indeed, equal to 3^n for some
non-negative integer n(for example 1= 3^0, 81=3^4, or 129140163 =
3^17), the program should tell the user that the input is a power of 3
and print the exponent n. If the input is a positive integer which is
not a power of 3, the program should print a corresponding message.
Finally, if the input is an integer less than 1, the program should
terminate with an appropriate error message. Here are four sample runs
of this program, assuming that the executable file is called
power_of_three.

Enter a positive integer: 81
81 is a power of 3, exponent = 4

Enter a positive integer: 1
1 is a power of 3, exponent = 0

Enter a positive integer: 12
12 is not a power of 3!

Enter a positive integer: -1
Error: invalid integer entered!

Note: the number 3 should be introduced into the program as a symbolic
constant BASE, using the #define compiler directive. It should not
appear anywhere else in the program. Moreover, the program should
continue working correctly when BASE is re-defined to stand for
another integer greater than 1, including all the messages that the
program prints out.
Hint: In order to check whether a given positive integer is a power of
3, you could use, for example, the while loop. Inside the loop, you
could use the modulo(%) and integer division(/) operators.
You can use the relational expression x<=y in order to test whether x
is less than or equal
to y. In order to test whether x is not equal to y, you can use the
expression x!=y.
If you'd like, you can use the following outline for your program:

#define BASE 3
int main()
{
int num,.....;
printf("Enter a positive integer: ");
scanf("%d", &num);
if (num<= 0)
{
{printf ("Error: invalid integer entered! ");
return 1;
}
                .
                .
                .
return 0;
}

Problem 4
Write a C program, called integer_sum.c, that computes the sum of
integers interactively provided by the user. At each iteration, the
program should print the number of integers that the user has entered
so far, along with a menu describing three possible acitons from which
the user could choose. The three possible actions are as follows:
1. Entering a new integer
2. Printing the sum of all the integers entered so far
3. Exiting the program

If the user enters a number other than 1,2, or 3 when presented with
this menu, the program should simply print the same menu again,
prompting the user to enter a new choice of action. You are not
required to introduce the constants 1,2, and 3 into the program using
#define, although you can do so. You can assume that when the user is
prompted to enter an integer, the user indeed enters an integer.

Here is one example run of such a program, assuming that the
executable file is called integer_sum. Note that the input from the
user is marked as underlined text below.

Welcome to the integer sum program!

So far, you have entered 0 numbers. You may:
1. Enter a new integer
2. Display the current sum
3. Exit
Please enter your choice: 2
The current sum is: 0
So far, you have entered 0 numbers. You may:
1. Enter a new integer
2. Display the current sum
3. Exit
Please enter your choice: 1
Enter the new integer: 30
So far, you have entered 1 numbers. you may:
1. Enter a new integer
2. Display the current sum
3. Exit
Please enter your choice: 1
Enter the new integer: -17
so far, you have entered 2 numbers. you may:
1. Enter a new integer
2. Display the current sum
3. Exit
Please enter your choice: 2
The current sum is 13
So far, you have entered 2 numbers. you may:
1. Enter a new integer
2. Display the current sum
3. Exit
Please enter your choice: 6
So far, you have entered 2 numbers. you may:
1. Enter a ne

Explanation / Answer

please rate - thanks

#include<stdio.h>
#include<conio.h>
int main()
{int a,b,c;
printf("enter integers a,b,c: ");
scanf("%d %d %d",&a,&b,&c);
printf("!a || !b++ && c: ");
if(!a || !b++ && c)
     printf("True ");
else
     printf("False ");
printf("(a-1 || b/2) && (c*=2): ");
if((a-1 || b/2) && (c*=2))
     printf("True ");
else
     printf("False ");
printf("(a-- || --b) && (c+=2): ");    
if((a-- || --b) && (c+=2))
     printf("True ");
else
     printf("False ");
printf("a || ! (b && --c): ");   
if(a || ! (b && --c))
     printf("True ");
else
     printf("False ");
getch();
return 0;
}
   
-------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{int num,digit,n=0;
printf("enter an integer: ");
scanf("%d",&num);
while(num>0)
   {n++;
    digit=num%10;
    num/=10;
    printf("Digit(%d): %d ",abs(n),digit);
   }  
getch();
return 0;
}

------------------------------------------------------------------------------------- #include<stdio.h>
#include<conio.h>
#include<math.h>
#define BASE 3
int main()
{int num,i=0,val=1,found=0;
printf("enter a positive integer: ");
scanf("%d",&num);
if(num<=0)
   printf("Error: invalid integer entered! ");
else
{ do
      {if(val==num)
          {printf("%d is a power of %d, exponent= %d ",num,BASE,i);
          found=1;
           }
        i++;
       val*=BASE;             
       }while(val<=num);
   if(found==0)
        printf("%d is not apower of %d! ",num,BASE);
   }
getch();
return 0;
}
      ------------------------------------------------------------------------------------------ #include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{int num,i=0,sum=0,choice;
printf("Welcome to the integer sum program! ");
for(;;)
{
printf("So far, you have entered %d numbers. Youmay: ",i);
printf("1. Enter a new integer ");
printf("2. Display the current sum ");
printf("3. Exit ");
scanf("%d",&choice);
if(choice==1)
     {printf("Enter the new integer: ");
      scanf("%d",&num);
      sum+=num;
      i++;
     }
else if(choice==2)
   printf("The current sum is %d ",sum);
else if(choice==3)
    return 0;
}
}