Question

In: Computer Science

Part A: Write a set of statements that declare a variable of type double called yourNum,...

Part A: Write a set of statements that declare a variable of type double called yourNum, then prompts the user to input a value which gets stored into that variable.

Part B: Write a set of statements that displays the phrase "Even Number!" when the value in the variable count is an even number but displays the phrase “That is odd” otherwise. Declare and initialize all variables.

Part C: Write the necessary code to swap (exchange) the values in two integer variables named oprahsIncome and myIncome . Declare and initialize all variables. You may declare and use only one additional variable.

Write in c language please !!!

Solutions

Expert Solution

Part(A) :

#include <stdio.h>

int main()
{
/* Declare a double variable yourNum*/
double yourNum;
  
printf("Enter a number :");
  
/* Prompt for input*/
scanf("%lf" ,&yourNum);
  
/* Print the entered number*/
printf("%lf",yourNum);

return 0;
}

==========================================================================================

Part(B) :

#include <stdio.h>

int main()
{
int count ;
printf("Enter a number: ");
  
/* Takes input and stored in variable count*/
scanf("%d", &count );

/* checks if input number is divisible by 2*/
if (count % 2 == 0) {
printf("Even Number!");
}
else {
printf("That is odd");
}
return 0;
}

===========================================================================================

Part(C) :

#include <stdio.h>
int main()
{
int oprahsIncome ,myIncome ;
  
printf("Enter value for oprahsIncome : ");
scanf("%d", &oprahsIncome );
  
printf("Enter value for myIncome : ");
scanf("%d", &myIncome );
  
  
//Swapping
int temp = oprahsIncome; //store value of oprahsIncome in temp variable
oprahsIncome = myIncome; //store value of myIncome in oprahsIncome variable
myIncome = temp; //store value of temp in myIncome variable,hence swapping done
  

  
printf("After Swapping: \noprahsIncome = %d, myIncome = %d", oprahsIncome, myIncome);
  
return 0;
}

===================================================================================

Please like it would be a lot for me.Thanks


Related Solutions

In Java form Declare and assign a char variable called myLetter to z. Write a Java...
In Java form Declare and assign a char variable called myLetter to z. Write a Java statement that makes myLetter uppercase. Write a java statement that finds out if myLetter is a digit. Write a java statement that finds out if myLetter is an upper case letter. Assume myLetter = ‘Z’; What is the output for System.out.print(myLetter++); Assume myLetter = ‘Z’; What is the output for System.out.print(++myLetter); Assume myLetter = ‘Z’; What is the output for System.out.print(myLetter--); What happens when...
****in java please*** Create a class CheckingAccount with a static variable of type double called interestRate,...
****in java please*** Create a class CheckingAccount with a static variable of type double called interestRate, two instance variables of type String called firstName and LastName, an instance variable of type int called ID, and an instance variable of type double called balance. The class should have an appropriate constructor to set all instance variables and get and set methods for both the static and the instance variables. The set methods should verify that no invalid data is set. Also...
Which of the following statements is NOT correct? A. It is allowed to declare a variable...
Which of the following statements is NOT correct? A. It is allowed to declare a variable and initialize it in one statement. B. Once a variable is declared and initialized, you can change its value later on. C. The variable declaration tells the compiler to allocate appropriate memory space for the variable based on its data type. D. It is allowed to declare two variables with the same name but with different data type.
Write a class named GasTank containing: An instance variable named amount of type double, initialized to...
Write a class named GasTank containing: An instance variable named amount of type double, initialized to 0. An instance variable named capacity of type double. A constructor that accepts a parameter of type double. The value of the parameter is used to initialize the value of capacity. A method named addGas that accepts a parameter of type double. The value of the amount instance variable is increased by the value of the parameter. However, if the value of amount is...
Update the function playScratchOffs to do the following Declare an integer variable to store the type...
Update the function playScratchOffs to do the following Declare an integer variable to store the type of scratch off (i.e. type) Declare an integer variable to store the number of scratch off (i.e. count) Declare an integer variable for loop control (i.e. c) Declare a variable of data type struct OneDollar (i.e. oneSO) Declare a variable of data type struct TwoDollar (i.e. twoSO) Declare a variable of data type struct FiveDollar (i.e. fiveSO) Write a series of printf statements to...
Write a program in c# that declare a variable and store user name jjohn in. Then,...
Write a program in c# that declare a variable and store user name jjohn in. Then, write a statement that will make your program display at the screen the content of that variable, followed by " I would like to know your height in centimeter. Please enter it:". Then, write a statement that will store the value entered by the user, allowing decimal numbers ie some precision, a fraction part. Finally, write statements (more than one can be needed) so...
Questions: 1) // declare integer variable sum equal to zero // declare variable integer i //...
Questions: 1) // declare integer variable sum equal to zero // declare variable integer i // declare while loop condition where i is less then 25 // inside of brackets calculate the sum of i (addition) // increment i // outside the loop print the sum of values ============================================= 2) Create a sentinel value example if I press number 0 it will display the sum of data // create a scanner // prompt the user to to enter the numbers...
Write a java code segment to declare an array of size 10 of type String and...
Write a java code segment to declare an array of size 10 of type String and read data for them from a file, prompt user for the file name. Data is stored in a file with 1 string per line.
swift language declare a Swift array variable that can hold instances of any class type
swift language declare a Swift array variable that can hold instances of any class type
Write a function that will take in an array (of type double), and will return the...
Write a function that will take in an array (of type double), and will return the array with all of the elements doubled. You must use pass-by-reference and addressing and/or pointers to accomplish this task. C++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT