Computer Science: A Structured Programming Approach Using C, Third Edition
3rd Edition
ISBN: 9780534491321
Author: Behrouz A. Forouzan, Richard F. Gilberg
Publisher: Course Technology, Inc.
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 2, Problem 31PS
Code the variable declarations for each of the following:
a. a short integer variable named code
b. a constant named salesTax initialized to .0825
c. a floating-point named sum of size double initialized to 0
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Give meaningful identifiers for the following variables and write a proper C++ declaration and initialization to a reasonable value. a. A variable to store the letter grade, (A, B, C, D, or F).b. A variable to store the sales tax price of an item.c. A variable to store the number of juice bottles sold.d. A variable to store the billing amount of a doctor’s visit.e. A variable to store the grade point average (GPA).
20. Give meaningful identifiers for the following variables and write a proper C11 declaration and initialization to a reasonable value. (1, 6, 7)a. A variable to store the letter grade, (A, B, C, D, or F).b. A variable to store the sales tax price of an item.c. A variable to store the number of juice bottles sold.d. A variable to store the billing amount of a doctor’s visit.e. A variable to store the grade point average (GPA).
Following is an example of different ways one can declare variables in some programming language.Write down the regular expression that can generate such variable declarations.Assume that-
All variable names are at most five (previously written as exactly five; both will be considered correct) characters long.
Variable names can contain only small letters [a-z], digits [0-9], and two special characters $ (dollar) and _ (underscore).
$ sign can only be used at the beginning.
No names can start with digits.
The variable types are integer, real, char, and Boolean only.
The word ‘var’ which denotes variable is optional.
Ignore any whitespace (space, tab, newline, etc.)
Infer the rest of the rules from the code snippets below-var int1 : integer;var foo_1 : boolean;var f2 : real;_ind: char;x, y, z: integer;
Chapter 2 Solutions
Computer Science: A Structured Programming Approach Using C, Third Edition
Ch. 2 - The purpose of a header file, such as stdio.h, is...Ch. 2 - Prob. 2PSCh. 2 - The C standard function that receives data from...Ch. 2 - Which of the following statements about the...Ch. 2 - Which of the following statements about block...Ch. 2 - Prob. 6PSCh. 2 - Which of the following is not a data type?...Ch. 2 - The code that establishes the original value for a...Ch. 2 - Prob. 9PSCh. 2 - Prob. 10PS
Ch. 2 - To print data left justified, you would use a in...Ch. 2 - Prob. 12PSCh. 2 - One of the most common errors for new programmers...Ch. 2 - Which of the following is not a character constant...Ch. 2 - Which of the following is not an integer constant...Ch. 2 - Which of the following is not a floating-point...Ch. 2 - Prob. 17PSCh. 2 - Which of the following is not a valid identifier...Ch. 2 - What is the type of each of the following...Ch. 2 - What is the type of each of the following...Ch. 2 - Which of the following identifiers are valid and...Ch. 2 - Which of the following identifiers are valid and...Ch. 2 - What is output from the following program...Ch. 2 - Prob. 24PSCh. 2 - Find any errors in the following program....Ch. 2 - Find any errors in the following program....Ch. 2 - Prob. 27PSCh. 2 - Prob. 28PSCh. 2 - Prob. 29PSCh. 2 - Code the variable declarations for each of the...Ch. 2 - Code the variable declarations for each of the...Ch. 2 - Write a statement to print the following line....Ch. 2 - Write a program that uses four print statements to...Ch. 2 - Write a program that uses four print statements to...Ch. 2 - Write a program that uses defined constants for...Ch. 2 - Prob. 36PSCh. 2 - Prob. 37PSCh. 2 - Write a program that prompts the user to enter an...Ch. 2 - Write a C program using printf statements to print...Ch. 2 - Write a program that reads a character, an...Ch. 2 - Write a program that prompts the user to enter...Ch. 2 - Write a program that reads 10 integers and prints...Ch. 2 - Write a program that reads nine integers and...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- a) in the following C code, which variable would most likely be overwritten by strcpy() and why? void f1(char *str2) { int y; char str1[10]; strcpy(str1, str2);arrow_forwardGive the declaration for two variables of type double. The variables are tobe named rate and time. Both variables should be initialized to zero inthe declaration.arrow_forwardIf the following code segment compiles correctly, what do you know about the variable x? if(x) WriteLine(OK); a. x is an integer variable. b. x is a Boolean variable. c. x is greater than 0. d. none of thesearrow_forward
- 8- Which of the following primitive types in Python would be most suitable for representing acceleration due to gravity on Earth, 9.81 m/s²? a. float (floating point number) b. str (string) c. bool (boolean) d. int (integer)arrow_forwardIs the following comment written using si ng le- line or multi-line comment symbols?II This program was written by M. A. Codewriterarrow_forwardWhich of the following is not a correct variable type? (a) Float (b) Real (c) Int (d) Double (e) Char.arrow_forward
- Please show me how to typecast a float variable to integer explicit with the help of a program in C++. Take the float value as float f= 12.91arrow_forwardWhat is the decimal-base value of the following octal/hex constants? 040 0X40 0XFF 0XCAB Write a C++ program that calculates sum of the first two values above.arrow_forwardFor each of the following variable definitions, determine whether the statementis valid or invalid. For those that are invalid , explain why .A) int ivar;int *i ptr = &ivar ;B) int ivar, *iptr = &ivar ;C) fl oat fvar;D) int *i ptr = &fvar ;int nums[50], *i ptr = nums;E) int *i ptr = &ivar ;int ivar;arrow_forward
- Another way to write this code. #Declare variables and constants year = 0 YEARLY_RISE = 1.80 #Print header print("Year\t\tRise (in millimeters)") print("\n--------------------------------------\n") #Iterate 25 times for i in range(1, 26): #Calculate the rise in millimeters print(f"{i}\t\t{YEARLY_RISE * i:.2f}")arrow_forwardDeclare a primitive variable of type integer named num and assign it the value 14.arrow_forwardCompute the values of the following C expressions assuming that a, b and c are integer variables and d is a float variable as declared below. int a=2, b=3, c=4; float d=5.0arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
What Are Data Types?; Author: Jabrils;https://www.youtube.com/watch?v=A37-3lflh8I;License: Standard YouTube License, CC-BY
Data Types; Author: CS50;https://www.youtube.com/watch?v=Fc9htmvVZ9U;License: Standard Youtube License