1.4
int age;// age of a persondoubleemployeeIncome;// employee incomelongwordsInDictn;// number of words in dictionarycharletter;// letter of alphabetchar*greeting;// greeting message
2.1
// test if
n
is even:n%2 == 0// test if
c
is a digit:c >= '0' && c <= '9'// test if
c
is a letter:c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'// test if
n
is odd and positive or
n
is even and negative:n%2 != 0 && n >= 0 || n%2 == 0 && n < 0// set the
n
-th bit of a long integer
f
to 1:f |= (1L << n)// reset the
n
-th bit of a long integer
f
to 0:f &= ~(1L << n)// give the absolute value of a number
n
:(n >= 0 ? n : -n)// give the number of characters in a null-terminated string literal
s
:sizeof(s) - 1
2.2
(((n <= (p + q)) && (n >= (p - q))) || (n == 0))(((++n) * (q--)) / ((++p) - q))(n | ((p & q) ^ (p << (2 + q))))((p < q) ? ((n < p) ? ((q * n) - 2) : ((q / n) + 1)) : (q - n))
2.3
double d = 2 * int(3.14);// initializes d to 6longk = 3.14 - 3;// initializes k to 0charc = 'a' + 2;// initializes c to 'c'charc = 'p' + 'A' - 'a';// initializes c to 'P'
2.4
#include <iostream.h>int main (void){long n;cout << "What is the value of n? ";cin >> n;cout << "2 to the power of " << n << " = " << (1L << n) << '\n';return 0;}
2.5
#include <iostream.h>int main (void){double n1, n2, n3;cout << "Input three numbers: ";cin >> n1 >> n2 >> n3;
231C++ ProgrammingCopyright © 1998 Pragmatix Software
Leave a Comment