In: Computer Science
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 !!!
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