QUESTION 1 What statement would you use to print the phrase “Hello, world” and t
ID: 667478 • Letter: Q
Question
QUESTION 1
What statement would you use to print the phrase “Hello, world” and then start a new line?
QUESTION 2
What statement would you use to assign the value 32 to the variable cheeses?
QUESTION 3
What statement would you use to read a value from keyboard input into the variable cheeses?
QUESTION 4
What statement would you use to print “We have X varieties of cheese,” where the current value of the cheeses variable replaces X?
QUESTION 5
Write a C program that displays your name and address (or if you value your privacy, a fictitious name and address).
QUESTION 6
Declare variables matching the following descriptions:
A short integer with the value 80
An unsigned int integer with the value 42,110
An integer with the value 3,000,000,000
QUESTION 7
Evaluate the following expressions as C++ would:
8 * 9 + 2
6 * 3 / 4
3 / 4 * 6
6.0 * 3 / 4
15 % 4
QUESTION 8
What is the variable type for each of the following declarations?
auto cars = 15;
auto iou = 150.37f;
auto level = 'B';
auto crat = U'/U00002155';
auto fract = 8.25f/2.5;
QUESTION 9
Construct logical expressions to represent the following conditions:
weight is greater than or equal to 115 but less than 125.
ch is q or Q.
x is even but is not 26.
x is even but is not a multiple of 26.
donation is in the range 1,000–2,000 or guest is 1.
QUESTION 10
Convert the following to a do/while loop. It should produce exactly the same output.
#include
int main(){
int i=0, k=0;
float j=0;
int counter = 10;
printf("Begin counting");
for (i=0; i < counter; i++) {
printf(i);
}
return 0;
}
-- Font family -- -- Font size -- -- Format --HeadingSub Heading 1Sub Heading 2ParagraphFormatted Code -- Font family --Andale MonoArialArial BlackBook AntiquaComic Sans MSCourier NewGeorgiaHelveticaImpactSymbolTahomaTerminalTimes New RomanTrebuchet MSVerdanaWebdingsWingdingsExplanation / Answer
Note : I have implemented the all the questions in C programming language.
Question 1:
To print the phrase Hello World we use
printf("Hello World ");
Here the "/n " will direct you the new line after printing the required statement.
Question 2:
Here first we declare the variable cheeses, as it is taking the integer values we will assign it as int.
int cheese =32; //declaring the variables and assigning it value 32.
Question 3:
As we have declared variables as integer(int) so we take input from the keyborad as follows:
printf("Enter the value of the Cheese");
scanf("%d", &cheese); // this will allow the user to input the value to the variable cheese.
Question 4 :
Let us assume that we have one more variable 'X'. now the code will look like this below:
int x=0; //initially we have provided zero as the intial value
x=cheese; //this will assign the value of varialble cheese to variable X.
printf(" We have %d varieties of cheese",x); // this will print the required output
Question 5:
To display the name and the address we need to take the 2 variables of string type.the program is as follows:
int main ()
{
char name[20]; //defined the variabla name
char address[20]; //defined the variable address
printf("enter the name ");
scanf("%s",name); //taking name from the keyborad
printf("enter the address");
scanf("%s",address); //taking address from keyborad
Now after getting the input we print the name and address in final.
printf( "the name is %s /n and the address is %s",name,address); //here the name and the address will be printed in the different line for improved readability.
return 0;
}
Question 6:
The variable declaration is as follows:
short a=80; //Here we have assumed variable 'a'.
unsigned int a=42110; //Comma are not allowed in the assignment.
Hence the compiler of C language are machine dependent, therefore some of them take 2 bytes of memory and some of them take 4 bytes of memory.
So such big value cannot be assigned of system which uses 2 bytes of memory. Therefore in system which takes 4 bytes of memory we will declare variable as
unsigned int a=3000000000;
Question 7:
The statement are as below:
printf("%d",(8*9)+2);
printf("%d",(6*3)/4);
printf("%d",(3/4)*6);
printf("%d",(6.0*3)/4);
printf("%d",15%4);
The value evaluated above are totally based on the associativity of the operator. Here there is confusion sometimes that which operation to be performed first,hence one should know the associativity of the operators in C.
Question 8:
The variable type is given as follows for each of the expression:
int //beacuse the varibale is being assigned the integer value.
float //the postfix 'f' after the variable represents the float variable type.
char // the character variable are always in the single quotes.
char // the single quote represents the variable of character type.
float // the float variable is being divided by float variable and hence comes out to be float value.
Question 9:
The logical expression of the statements are as follows:
(weight>=115 && weight<125 ) //Here we assume weight as the integer variable.
(ch== 'q' || ch== "Q' ) //Here we assume ch is character variable.
(x%2==0 && x!=26) //Here % operator will check for the even number.
((x%2)==0 && (x%26)!=0) //Check for the even and the divisibility too.
((donation>=1000 && donation<=2000) || guest ==1) //We assume that guest and donation are the variables.
Question 10.
The modified code is as below:
#include<stdio.h>
int main()
{
int i=0, k=0;
float j=0;
int counter = 10;
printf("Begin counting");
do{ //It will keep on looping and printing till while condition evaluates to flase.
printf(i);
}while(counter!=0);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.