SlideShare a Scribd company logo
UNIVERSITI TUN HUSSEIN ONN MALAYSIA
         FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING
         BTI 10202: COMPUTER PROGRAMMING


                              REVISION EXERCISES
 NAME       : _SCHEMA________________________________

 MATRICS NO.: _______________            DATE : _____________


1. Determine, as best you can, the purpose of each of the following C programs. Identify all
variables within each program. Identify all input and output statements, all assignment
statements, and any other special features that you recognize.

       int smaller ( int a, int b);
       main( )
       {
       int a, b, min;
       printf ( "Please enter the first number: " ) ;
       scanf ("%d" , &a) ;
       printf ("Please enter the second number: " ) ;
       scanf ( "%d", &b);
       min = smaller(a, b);
       printf ( "  n The smaller number is : %d", min);

       int smaller ( int a, int b)
       {
       if (a <= b)
       return(a);
       else
       return(b);
       }


This program uses a function to determine the smaller of two integer quantities.
The variables are a, b and min.
The alternating pairs of printf - scanf statements provide interactive input.
The final printf statement is an output statement.
The statement min = smaller (a, b) references the function, which is
called smaller.
This function contains an if - else statement that returns the smaller of the two
quantities to the main portion of the program.

2. Determine which of the following are valid identifiers. If invalid, explain why.
(a) record1          (e) $tax               (h) name_and_address
(b) 1record          (f) name               (i) name-and-address
(c) file_3           (g) name and address (j) 123-45 -6789
(d) return

a.Valid
b.An identifier must begin with a letter.
c.Valid
d.return is a reserved word.
e.An identifier must begin with a letter.
f.Valid
g.Blank spaces are not allowed.
h.Valid
i.Dash (minus sign) is not allowed.
j. An identifier must begin with a letter or an underscore.

3. Write appropriate declarations for each group of variables and arrays.
       (a) Integer variables: p, q
           Floating-point variables: x , y , z
           Character variables: a, b, c

       (b) Floating-point variables: root1 , root2
          Long integer variable: counter
          Short integer variable: f l a g

(a) int p, q;         (b) float rootl , root2;
   float x, y, z;         long counter;
   char a, b , c ;        short flag;



4. Explain the purpose of each of the following expressions.
   (a) a - b           (d) a >= b            (f) a < ( b / c )
   (b) a * (b + c)     (e) (a % 5 ) == 0     (g) --a
   (c) d = a * (b + c)

a. Subtract the value of b from the value of a.
b. Add the values of b and c, then multiply the sum by the value of a.
c. Add the values of b and c and multiply the sum by the value of a. Then assign the result to
d.
d. Determine whether or not the value of a is greater than or equal to the value of b. The
result will be either true or false, represented by the value 1 (true) or 0 (false).
e. Divide the value of a by 5, and determine whether or not the remainder is equal to zero.
The result will be either true or false.
f. Divide the value of b by the value of c, and determine whether or not the value of a is less
than the quotient. The result will be either true or false.
g. Decrement the value of a; i.e., decrease the value of a by 1.

5. Suppose a, b and c are integer variables that have been assigned the values a = 8, b = 3 and c =-
5. Determine the value of each of the following arithmetic expressions.
       (a) a + b + c                   (f) a % c
       (b) 2 * b + 3 * ( a - c )       (g) a * b / c
(c) a / b                            (h) a * (b / c)
         (d) a % b                            (i) (a * c) % b
         (e) a / c                            (j) a * (c % b)


                      (a)   6     (f)   3
                      (b)   45    (g)   -4
                      (c)   2     (h)   0 (because b / c is zero)
                      (d)   2     (i)   -1
                      (e)   -1    (j)   -16


6. Suppose x, y and z are floating-point variables that have been assigned the values x = 8.8, y =
3.5 and z = -5.2.
Determine the value of each of the following arithmetic expressions.
(a) x + y + z
(b) 2 * y + 3 * ( x - z )
(c) x / y
(d) x % y

 (a)    7.1
 (b)    49
 (c)    2.51429
 (d)    The remainder operation is not defined for floating-point operands

7. A C program contains the following declarations and initial assignments:
       int i= 8, j = 5, k;
       float x = 0.005, y = -0.01, z;
       char a, b, c = ' c ' , d = ‘d ' ;
Determine the value of each of the following assignment expressions. Use the values originally
assigned to the variables for each expression.


   (a) k = (i + j )         (i) z = k = x
   (b) z = (x + y)          (j) k = z = x
   (c) i = j                (k) i += 2
   (d) k = (x + y)          (l) y -= x
   (e) k = c                (m) x *= 2
   (f) z = i / j            (n) i /= j
   (g) a = b = d            (o) i %= j
   (h) i= j = 1.1           (p) i+= ( j - 2)

(a) k= 13                               (i)        k = 0, z = 0.0
(b) z = -0.005                          (j)        z = 0.005, k = 0 [compare with (i)
                                                   above]
(c)    i=5                              (k)        i= 10
(d)    k=0                              (l)        y = -0.015
(e)    k = 99                           (m)        x = 0.010
(f)    z = 1.0                          (n)        i=l
(g) b = 100, a = 100 (Note     (o)          i=3
    that 100 is the encoded
    value for 'd’ in the ASCII
    character set.)
(h) j = l , i = l              (p)          i= 11

8. A C program contains the following declarations and initial assignments:
         int i = 8, j = 5;
         double x = 0.005, y = -0.01;
         char c = 'c’ , d = ‘d';
Determine the value of each of the following expressions, which involve the use of library
functions.
(a) abs(i - 2 * j )
(b) fabs(x + y)
(c) ceil(x)
 (d) ceil(x + y)                                (a) 2                (i) 0.005
(e) floor(x)                                    (b) 0.005            (j) 0.011180
(f) floor(x + y)                                (c) 1.0              (k) 0.014999
(g) exp(x)                                      (d) 0.0              (l) 1.002472
(h) log(x)                                      (e) 0.0
(i) log(exp(x))                                 (f) -1.0
(j) sqrt(x*x + y*y)                             (g) 1.005013
(k) sin(x - y)                                  (h) -5.298317
(l) sqrt(sin(x) + cos(y))

9. A C program contains the following statements:
        #include <stdio.h>
        char a, b, c;
(a) Write appropriate getchar statements that will allow values for a, b and c to be entered into the
computer.
(b) Write appropriate putchar statements that will allow the current values of a, b and c to be
written out of the computer (i.e., to be displayed).

        (a)    a = getchar();         (b)   putchar (a) ;
               b = getchar();               putchar(b);
               c = getchar();               putchar(c);

10. Solve Prob. 9 using a single scanf function and a single print f function rather than the getchar
and putchar statements.
       (a) scanf ( "%c%c%c", &a, &b,              (b) printf(n%c%c%c”, a, b, c);
            &c) ;                                       or printf ( " % c %c %c”, a, b,
            or scanf ("%c %c %c", &a,                   c);
            &b, &c);

11. A C program contains the following statements:
       #include <stdio.h>
       int i, j, k;
Write a printf function for each of the following groups of variables or expressions. Assume all
variables represent decimal integers.
        (a) i, j and k
        (b) (i + j), (i - k)
        (c) sqrt(i + j),abs(i - k)


                          (a) printf (“%d %d %d”, i,j, k);
                          (b) printf ( "%d %d", (i+ j ) , ( i - k));
                          (c) printf ( "% f %d", sqrt(i + j) , abs(i - k));


12. A C program contains the following statements.
       #include <stdio.h>
       char text [ 80];
Write a printf function that will allow the contents of text to be displayed in the following ways.
       (a) Entirely on one line.
       (b) Only the first eight characters.
       (c) The first eight characters, preceded by five blanks.
       (d) The first eight characters, followed by five blanks.

                                  (a)   printf ( “ %s" , text ) ;
                                  (b)   printf("%.8s", text ) ;
                                  (c)   printf ( "%13.8s", text ) ;
                                  (d)   printf ( "%-13.8s”, text ) ;

13. A C program contains the following array declaration.
        char text[80];
Suppose that the following string has been assigned to text.
Programming with C can be a challenging creative activity.
Show the output resulting from the following printf statements.
(a) printf ( "%s", text ) ;           (d) printf ( "%18.7s", text ) ;
(b) printf ("%18s", text ) ;          (e) printf ( " % -18.7s " , text ) ;
(c) printf ( “%.18s", text ) ;
(a) Programming with C can be a challenging creative activity.
(b) Programming with C can be a challenging creative activity.
(c) Programming with C
(d)                   Program
(e) Program


14. Write a switch statement that will examine the value of a char-type variable called color and
print one of the following messages, depending on the character assigned to color.
        (a) RED, if either r or R is assigned to color,
        (b) GREEN, if either g or G is assigned to color,
        (c) BLUE, if either b or B is assigned to color,
        (d) BLACK, if color is assigned any other character
(a) switch (color) {
                           case ‘r':
                           case ' R ' : printf ( “RED") ; break;
                       (b) case ' g ‘ :
                           case ' G ' : printf ("GREEN” ) ; break;
                       (c) case ' b ' :
                           case ' B ' :
                           printf ( ''BLUE"); break;
                       (d) default :
                           printf ( “BLACK") ; break;


15. Write an appropriate control structure that will examine the value of a floating-point variable
called temp and print one of the following messages, depending on the value assigned to temp.
        (a) ICE, if the value of temp is less than 0.
        (b) WATER, if the value of temp lies between 0and 100.
        (c) STEAM, if the value of temp exceeds 100.
Can a switch statement be used in this instance?

            if (temp < 0.)
            printf ( " ICE");
            else if (temp >= 0. && temp <= 100.)
            printf ( "WATER') ;
            else
            printf("STEAM") ;
            A switch statement cannot be used because:
            (a) The tests involve floating-point quantities rather than integer
            quantities.
            (b) The tests involve ranges of values rather than exact values.

16. Describe the output that will be generated by each of the following C program.

     #include <stdio. h>
     main ( ) {
        int i = 0, x = 0;
        while(i<20){                                  0 5 15 30
     if (i % 5 == 0) {
     x += i;                                          x = 30
     printf("%d ", x);
     }
        ++i ;
            }
        printf('nx = %d", x);
     }


17. What is meant by a function call? From what parts of a program can a function be called?
accessing a function by specifying its name, followed by a list g arguments enclosed in
parentheses and separated by commas. If the function call does not require any arguments,
an empty pair of parentheses must follow the name of the function. . Function call can be a
part of a simple expression (such as an assignment statement) or may be one of the operands
(3+5, 3 and 5are operands) within more complex expression or directly from printf.

18. Can a function be called from more than one place within a program? Yes

19. When a function is accessed, must the names of the actual arguments agree with the names of
the arguments in the corresponding function prototype? No

20. Each of the following is the first line of a function definition. Explain the meaning of each.
(a) float f ( float a, float b) (c) void f ( int a)
(b) long f (long a)             (d) char f (void)


(a)   f accepts two floating-point arguments and returns a floating-point value.
(b)   f accepts a long integer and returns a long integer.
(c)   f accepts an integer and returns nothing.
(d)   f accepts nothing but returns a character.

21. Write an appropriate function call (function access) for each of the following functions.
(a) float formula(f1oat x)            (b) void display ( int a, int b)
{                                              {
float y;                                       int c;
y = 3 * x - 1;                                 c = sqrt(a * a + b * b);
return ( y ) ;                        printf ( " c = % i  n " , c ) ;
}                                              }

                                   (a) y = formula(x);
                                   (b) display(a, b);


22. Write the first line of the function definition, including the formal argument declarations, for
each of the situations described below.
(a) A function called sample generates and returns an integer quantity.
(b) A function called root accepts two integer arguments and returns a floating-point result.
(c) A function called convert accepts a character and returns another character.
(d) A function called transfer accepts a long integer and returns a character.
(e) A function called inverse accepts a character and returns a long integer.
(f) A function called process accepts an integer and two floating-point quantities (in that order),
and returns a double-precision quantity.

                          (a)   int sample(void)
                          (b)   float root ( int a , int b)
                          (c)   char convert (char c)
                          (d)   char transfer(1ong i )
                          (e)   long inverse(char c)
                          (f)   double process(int i, float a, float b)
23. Explain the meaning of each of the following declarations.
(a) int *px;
(b) float a = -0.167;
     float *pa = &a;

(a) px is a pointer to an integer quantity.
(b) a is a floating-point variable whose initial value is -0.167; pa is a pointer to a
    floating-point quantity; the address of a is assigned to pa as an initial value.

24. A C program contains the following statements.
        float a = 0.001, b = 0.003;
        float c, *pa, *pb;
        pa = &a;
        *pa = 2 * a;
        pb = &b;
        c = 3 * (*pb - *pa);
Suppose each floating-point number occupies 4 bytes of memory. If the value assigned to a begins
at (hexadecimal) address 1130, the value assigned to b begins at address 1134, and the value
assigned to c begins at 1138, then
(a) What value is assigned to &a?
(b) What value is assigned to &b?
(c) What value is assigned to &c?
(d) What value is assigned to pa?
(e) What value is represented by *pa?
(f) What value is represented by &( *pa)?
(g) What value is assigned to pb?
(h) What value is represented by *pb?
(i) What value is assigned to c?

(a)   1130
(b)   1134
(c)   1138
(d)   1130
(e)   0.002
(f)   &(*pa) = pa = 1130
(g)   1134
(h)   0.003
(i)   0.003


Multiple selection questions
1. Which of the following is the correct variable definition?
        a.   123_name               b.    &name

        c.   Name_1                 d.    #name@
2. Which of the following is not a data type in C?
        a.   Integer                 b.    Double

        c.   data                    d.    unsigned

3. How would you assign the value 3.14 to a variable called pi?
        a.   int pi;                 b.    unsigned pi;
               pi=3.14;                      pi=3.14;

        c.   string pi;              d.    float pi;
               pi=3.14;                      pi=3.14;
4. A common mistake for new students is reversing the assignment statement. Suppose you want
to assign the value stored in the variable "pi" to another variable, say "pi2":

       i. What is the correct statement?
        a.   pi2 = pi;               b.    pi = pi2;

       ii. What is the reverse? Is this a valid C statement (even if it gives incorrect results)?
        a.   pi2 = pi; is a valid C statement if pi     b.     pi = pi2; is a valid C statement if
             is not a constant.                                pi is not a constant.


iii. What if you wanted to assign a constant value (like 3.1415) to "pi2": What would the correct
statement look like? Would the reverse be a valid or invalid C statement?
        a.   pi2 = 3.1415;                              b.     3.1415 = pi2;
             The reverse is not a valid                        The reverse is a valid statement.
             statement.
5. scanf() is a very powerful function. What does it do?

a.   scanf  echos characters from the standard input, interprets them according to the
     specification in format, and stores the results through the remaining arguments.

b.   scanf  displays characters from the standard input, interprets them according to the
     specification in format, and stores the results through the remaining arguments.

c.   scanf   is the input analog of printf, providing many of the same conversion
     facilities in the opposite direction.

d.   scanf   is the output analog of printf, providing many of the same conversion
     facilities in the opposite direction.

6. Write the scanf() function call that will read into the variable "var":
       i. a float ii. an int iii. a double
a.    scanf("%f",&var);                    b.    scanf("%f",&var);
              scanf("%d",&var);                          scanf("%d",&var);
              scanf("%d", &var);                         scanf("%lf", &var);

        c.    scanf("%f",&var);                    d.    scanf("%f",&var);
              scanf("%i",&var);                          scanf("%d",&var);
              scanf("%u", &var);                         scanf("%s", &var);

7. What is the output for the following program?

   #include<stdio.h>

             main()
             {
                      int a,b;
                      float c,d;

                      a = 18;
                      b = a / 2;
                      printf("%dn",b);
                      printf("%2dn",b);
                      printf("%04dn",b);

               c = 18.3;
               d = c / 3;
               printf("%5.3fn",d);
               printf(":%-15.10s:n", "Are
   you ready?!");
           getch();
         }




             a.   9                        b.   9
                  9                              9
                  0009                          0009
                  6.100                         6.100
                  :Are you re      :            :Are you re       :

             c.   9                        d.   9
                   9                             9
                  0009                          0009
                  6.100                         6.10
                  :Are you read        :        :Are you re   :
8. Which of the following flowchart is best suitable for multiple choices problem?

(a) While, for, do-while                            (b) If – else selection




(c) Case structures
9. Write a complete program that outputs a right isosceles (with (at least) two equal sides) triangle
of height and width n, so n = 6 would look like

*
**
***
****
*****
******

The triangle function is given as below:

void isosceles(int n)
{
    int x,y;
    for (y= 0; y < n; y++)
    {
        for (x= 0; x <= y; x++)
             putchar('*');
        putchar('n');
    }
}


         a.   #include<stdio.h>                     b.   #include<stdio.h>
              #include<conio.h>                          #include<conio.h>

              void isosceles(int n);                     void isosceles(int n)
                                                         {
                     main()                                 int x,y;
                     {                                      for (y= 0; y < n; y++)
              int n;                                        {
              printf("n insert no of rows of                  for (x= 0; x <= y; x++)
              your triangle:");                                   putchar('*');
              scanf("%d",&n);                                  putchar('n');
              isosceles(n);                                 }
                                                         }
              getch();                                   main()
              }                                          {
              void isosceles(int n)                      int n;
              {                                          printf("n insert no of rows of your
                int x,y;                                 triangle:");
                for (y= 0; y < n; y++)                   scanf("%d",&n);
                {
                   for (x= 0; x <= y; x++)               getch();
                     putchar('*');                       }
                   putchar('n');
                }
              }

         c.   #include<stdio.h>                     d.   #include<stdio.h>
              #include<conio.h>                          #include<conio.h>
void isosceles(int n);                     void isosceles(int n)
                                                        {
                    main()                                int x,y;
                    {                                     for (y= 0; y < n; y++)
             int n;                                       {
             printf("n insert no of rows of your            for (x= 0; x <= y; x++)
             triangle:");                                       putchar('*');
             scanf("%d",&n);                                 putchar('n');
                                                          }
             getch();                                   }
             }
             void isosceles(int n)                             main()
             {                                                 {
               int x,y;                                 int n;
               for (y= 0; y < n; y++)                   printf("n insert no of rows of your
               {                                        triangle:");
                  for (x= 0; x <= y; x++)               isosceles(n);
                     putchar('*');
                  putchar('n');                        getch();
               }                                        }
             }


10. What is the correct output of the following code?

     #include <stdio.h>
     #include <conio.h>                                            a.   Please input two numbers
                                                                        to be multiplied: 1
     int mult ( int x, int y );                                         5
                                                                        The product of your two
     int main()
     {
                                                                        numbers is 5
       int x;
       int y;                                                      b.   Please input two numbers to
                                                                        be multiplied: 1
       printf( "Please input two                                        5
     numbers to be multiplied: " );
       scanf( "%d", &x );                                               The product of your two
       scanf( "%d", &y );                                               numbers is 15
       printf( "The product of your
     two numbers is %dn", mult( x,                                c.   The product of your two
     y ) );
       getch();
                                                                        numbers is 15
     }
                                                                   d.   The product of your two
     int mult (int x, int y)                                            numbers is 5
     {
       return x * y;
     }
11. How many functions are there (including main function) in the coding?


     #include<stdio.h>
     #include<conio.h>

     void myFunction();
     int add(int, int);

     int main()
     {
             myFunction();
             printf("nn%d",add(10,15));

               getch();
     }

     void myFunction()
     {
             printf("This is inside function :D");
     }

     int add(int a, int b)
     {
             return a+b;
     }




                a.   1
                b.   2
                c.   3
                d.   4

12. What is the output of the program in Ques.11?


                a.   This is inside function :D
                b.   25
                c.   25

                     This is inside function :D
                d.   This is inside function :D

                     25

13. Below are the advantages of using functions except?

a.   It makes possible top down modular programming. In this style of programming, the
     high level logic of the overall problem is solved first while the details of each lower
     level functions is addressed later.
b.   The length of the source program can be reduced by using functions at appropriate
     places.

c.   It becomes complicated to locate and separate a faulty function for further
     study.

d.   A function may be used later by many other programs this means that a c
     programmer can use function written by others, instead of starting over from scratch.

14. The correct output for the following function is:

       #include<stdio.h>
       #include<conio.h>
       void add(int x,int y)
       {
       int result;
       result = x+y;
       printf("Sum of %d and %d
       is %d.nn",x,y,result);
       }
       main()
       {
       add(10,15);
       add(55,64);
       add(168,325);
       getch();
       }




a.   Sum of 10 and 15 is 25.
     Sum of 55 and 64 is 119.
     Sum of 168 and 325 is 493.

b.   Sum of 10 and 15 is 25.
     Sum of 168 and 325 is 493.
     Sum of 55 and 64 is 119.

c.   Sum of 20 and 15 is 25.
     Sum of 65 and 64 is 119.
     Sum of 168 and 325 is 493.

d.   Sum of 55 and 64 is 117.
     Sum of 10 and 15 is 25.
     Sum of 168 and 325 is 493.

More Related Content

What's hot

Materi Rangkaian Arus Bolak - Balik (AC) lengkap (kelas 12 SMA)
Materi Rangkaian Arus Bolak - Balik (AC) lengkap (kelas 12 SMA)Materi Rangkaian Arus Bolak - Balik (AC) lengkap (kelas 12 SMA)
Materi Rangkaian Arus Bolak - Balik (AC) lengkap (kelas 12 SMA)
MayangPuspita2
 
Fluks Listrik dan Hukum Gauss
Fluks Listrik dan Hukum GaussFluks Listrik dan Hukum Gauss
Fluks Listrik dan Hukum Gauss
anggundiantriana
 
TEOREMA DE MORGAN DAN RANGKAIAN EXCLUSIVE OR
TEOREMA DE MORGAN DAN RANGKAIAN EXCLUSIVE ORTEOREMA DE MORGAN DAN RANGKAIAN EXCLUSIVE OR
TEOREMA DE MORGAN DAN RANGKAIAN EXCLUSIVE ORDaya Prisandi
 
Second order circuits linear circuit analysis
Second order circuits linear circuit analysisSecond order circuits linear circuit analysis
Second order circuits linear circuit analysis
ZulqarnainEngineerin
 
Fluks listrik, hukum gauss, dan teorema divergensi.
Fluks listrik, hukum gauss, dan teorema divergensi.Fluks listrik, hukum gauss, dan teorema divergensi.
Fluks listrik, hukum gauss, dan teorema divergensi.
Satria Wijaya
 
Automatic Volatage Regulator (AVR) Pertemuan 1
Automatic Volatage Regulator (AVR) Pertemuan 1Automatic Volatage Regulator (AVR) Pertemuan 1
Automatic Volatage Regulator (AVR) Pertemuan 1jajakustija
 
Gate ee 2007 with solutions
Gate ee 2007 with solutionsGate ee 2007 with solutions
Gate ee 2007 with solutions
khemraj298
 
Hukum Ampere Untuk Rangkaian Listrik
Hukum Ampere Untuk Rangkaian ListrikHukum Ampere Untuk Rangkaian Listrik
Hukum Ampere Untuk Rangkaian Listrik
Reynes E. Tekay
 
Ii Rangkaian Listrik Fasor
Ii Rangkaian Listrik FasorIi Rangkaian Listrik Fasor
Ii Rangkaian Listrik FasorFauzi Nugroho
 
6 faktor daya
6  faktor daya6  faktor daya
6 faktor daya
Simon Patabang
 
Modul 2 aljabar boole dan hukum de morgan ok
Modul 2   aljabar boole dan hukum de morgan okModul 2   aljabar boole dan hukum de morgan ok
Modul 2 aljabar boole dan hukum de morgan ok
Zony MuttaQin
 
01 merancang fet mosfet
01 merancang fet mosfet01 merancang fet mosfet
01 merancang fet mosfet
agus saefudin
 
Medan elektromagnetik 2
Medan elektromagnetik 2Medan elektromagnetik 2
Medan elektromagnetik 2
sinta novita
 
12 rangkaian rlc pararel
12 rangkaian rlc  pararel12 rangkaian rlc  pararel
12 rangkaian rlc pararel
Simon Patabang
 
Transistor
TransistorTransistor
Transistor
Firda Purbandari
 
The logic gate circuit
The logic gate circuitThe logic gate circuit
The logic gate circuitroni Febriandi
 
Analisa sistem tenaga(sistem per unit)-1
Analisa sistem tenaga(sistem per unit)-1Analisa sistem tenaga(sistem per unit)-1
Analisa sistem tenaga(sistem per unit)-1Faizin Pass
 
RESISTANSI SERI, PARALEL, DAN GABUNGAN
RESISTANSI SERI, PARALEL, DAN GABUNGANRESISTANSI SERI, PARALEL, DAN GABUNGAN
RESISTANSI SERI, PARALEL, DAN GABUNGAN
PRAMITHA GALUH
 
GAYA MAGNETIK.ppsx
GAYA MAGNETIK.ppsxGAYA MAGNETIK.ppsx
GAYA MAGNETIK.ppsx
SMAN 1 SUKATANI
 
Bab 11 - Kestabilan Sistem Kendali Digital.pdf
Bab 11 - Kestabilan Sistem Kendali Digital.pdfBab 11 - Kestabilan Sistem Kendali Digital.pdf
Bab 11 - Kestabilan Sistem Kendali Digital.pdf
bobbysarathoga
 

What's hot (20)

Materi Rangkaian Arus Bolak - Balik (AC) lengkap (kelas 12 SMA)
Materi Rangkaian Arus Bolak - Balik (AC) lengkap (kelas 12 SMA)Materi Rangkaian Arus Bolak - Balik (AC) lengkap (kelas 12 SMA)
Materi Rangkaian Arus Bolak - Balik (AC) lengkap (kelas 12 SMA)
 
Fluks Listrik dan Hukum Gauss
Fluks Listrik dan Hukum GaussFluks Listrik dan Hukum Gauss
Fluks Listrik dan Hukum Gauss
 
TEOREMA DE MORGAN DAN RANGKAIAN EXCLUSIVE OR
TEOREMA DE MORGAN DAN RANGKAIAN EXCLUSIVE ORTEOREMA DE MORGAN DAN RANGKAIAN EXCLUSIVE OR
TEOREMA DE MORGAN DAN RANGKAIAN EXCLUSIVE OR
 
Second order circuits linear circuit analysis
Second order circuits linear circuit analysisSecond order circuits linear circuit analysis
Second order circuits linear circuit analysis
 
Fluks listrik, hukum gauss, dan teorema divergensi.
Fluks listrik, hukum gauss, dan teorema divergensi.Fluks listrik, hukum gauss, dan teorema divergensi.
Fluks listrik, hukum gauss, dan teorema divergensi.
 
Automatic Volatage Regulator (AVR) Pertemuan 1
Automatic Volatage Regulator (AVR) Pertemuan 1Automatic Volatage Regulator (AVR) Pertemuan 1
Automatic Volatage Regulator (AVR) Pertemuan 1
 
Gate ee 2007 with solutions
Gate ee 2007 with solutionsGate ee 2007 with solutions
Gate ee 2007 with solutions
 
Hukum Ampere Untuk Rangkaian Listrik
Hukum Ampere Untuk Rangkaian ListrikHukum Ampere Untuk Rangkaian Listrik
Hukum Ampere Untuk Rangkaian Listrik
 
Ii Rangkaian Listrik Fasor
Ii Rangkaian Listrik FasorIi Rangkaian Listrik Fasor
Ii Rangkaian Listrik Fasor
 
6 faktor daya
6  faktor daya6  faktor daya
6 faktor daya
 
Modul 2 aljabar boole dan hukum de morgan ok
Modul 2   aljabar boole dan hukum de morgan okModul 2   aljabar boole dan hukum de morgan ok
Modul 2 aljabar boole dan hukum de morgan ok
 
01 merancang fet mosfet
01 merancang fet mosfet01 merancang fet mosfet
01 merancang fet mosfet
 
Medan elektromagnetik 2
Medan elektromagnetik 2Medan elektromagnetik 2
Medan elektromagnetik 2
 
12 rangkaian rlc pararel
12 rangkaian rlc  pararel12 rangkaian rlc  pararel
12 rangkaian rlc pararel
 
Transistor
TransistorTransistor
Transistor
 
The logic gate circuit
The logic gate circuitThe logic gate circuit
The logic gate circuit
 
Analisa sistem tenaga(sistem per unit)-1
Analisa sistem tenaga(sistem per unit)-1Analisa sistem tenaga(sistem per unit)-1
Analisa sistem tenaga(sistem per unit)-1
 
RESISTANSI SERI, PARALEL, DAN GABUNGAN
RESISTANSI SERI, PARALEL, DAN GABUNGANRESISTANSI SERI, PARALEL, DAN GABUNGAN
RESISTANSI SERI, PARALEL, DAN GABUNGAN
 
GAYA MAGNETIK.ppsx
GAYA MAGNETIK.ppsxGAYA MAGNETIK.ppsx
GAYA MAGNETIK.ppsx
 
Bab 11 - Kestabilan Sistem Kendali Digital.pdf
Bab 11 - Kestabilan Sistem Kendali Digital.pdfBab 11 - Kestabilan Sistem Kendali Digital.pdf
Bab 11 - Kestabilan Sistem Kendali Digital.pdf
 

Similar to Revision1schema C programming

(Www.entrance exam.net)-tcs placement sample paper 2
(Www.entrance exam.net)-tcs placement sample paper 2(Www.entrance exam.net)-tcs placement sample paper 2
(Www.entrance exam.net)-tcs placement sample paper 2Pamidimukkala Sivani
 
important C questions and_answers praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomesh
praveensomesh
 
C MCQ
C MCQC MCQ
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
KavyaSharma65
 
Technical questions
Technical questionsTechnical questions
Technical questions
Kirthan S Holla
 
Project2
Project2Project2
Project2?? ?
 
Ramco Sample Paper 2003
Ramco  Sample  Paper 2003Ramco  Sample  Paper 2003
Ramco Sample Paper 2003
ncct
 
c programs.pptx
c programs.pptxc programs.pptx
c programs.pptx
LavanyaDiet1
 
09 a1ec01 c programming and data structures
09 a1ec01 c programming and data structures09 a1ec01 c programming and data structures
09 a1ec01 c programming and data structuresjntuworld
 
MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdf
ahmed8651
 
Model question paper_mc0061
Model question paper_mc0061Model question paper_mc0061
Model question paper_mc0061
gurbaxrawat
 
Chapter 5 Balagurusamy Programming ANSI in c
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in c
BUBT
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
Koshy Geoji
 
Gate Computer Science Solved Paper 2007
Gate Computer Science Solved Paper 2007 Gate Computer Science Solved Paper 2007
Gate Computer Science Solved Paper 2007
Rohit Garg
 
Data structures and algorithms unit i
Data structures and algorithms unit iData structures and algorithms unit i
Data structures and algorithms unit i
sonalisraisoni
 
Cs101 endsem 2014
Cs101 endsem 2014Cs101 endsem 2014
Cs101 endsem 2014
RamKumar42580
 

Similar to Revision1schema C programming (20)

Revision1 C programming
Revision1 C programmingRevision1 C programming
Revision1 C programming
 
(Www.entrance exam.net)-tcs placement sample paper 2
(Www.entrance exam.net)-tcs placement sample paper 2(Www.entrance exam.net)-tcs placement sample paper 2
(Www.entrance exam.net)-tcs placement sample paper 2
 
important C questions and_answers praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomesh
 
C MCQ
C MCQC MCQ
C MCQ
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 
Technical questions
Technical questionsTechnical questions
Technical questions
 
Project2
Project2Project2
Project2
 
Ramco Sample Paper 2003
Ramco  Sample  Paper 2003Ramco  Sample  Paper 2003
Ramco Sample Paper 2003
 
c programs.pptx
c programs.pptxc programs.pptx
c programs.pptx
 
09 a1ec01 c programming and data structures
09 a1ec01 c programming and data structures09 a1ec01 c programming and data structures
09 a1ec01 c programming and data structures
 
MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdf
 
Exam for c
Exam for cExam for c
Exam for c
 
Model question paper_mc0061
Model question paper_mc0061Model question paper_mc0061
Model question paper_mc0061
 
Chapter 5 Balagurusamy Programming ANSI in c
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in c
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
random test
random testrandom test
random test
 
Gate Computer Science Solved Paper 2007
Gate Computer Science Solved Paper 2007 Gate Computer Science Solved Paper 2007
Gate Computer Science Solved Paper 2007
 
Data structures and algorithms unit i
Data structures and algorithms unit iData structures and algorithms unit i
Data structures and algorithms unit i
 
Cs101 endsem 2014
Cs101 endsem 2014Cs101 endsem 2014
Cs101 endsem 2014
 
Struct examples
Struct examplesStruct examples
Struct examples
 

Recently uploaded

Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 

Recently uploaded (20)

Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 

Revision1schema C programming

  • 1. UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI 10202: COMPUTER PROGRAMMING REVISION EXERCISES NAME : _SCHEMA________________________________ MATRICS NO.: _______________ DATE : _____________ 1. Determine, as best you can, the purpose of each of the following C programs. Identify all variables within each program. Identify all input and output statements, all assignment statements, and any other special features that you recognize. int smaller ( int a, int b); main( ) { int a, b, min; printf ( "Please enter the first number: " ) ; scanf ("%d" , &a) ; printf ("Please enter the second number: " ) ; scanf ( "%d", &b); min = smaller(a, b); printf ( " n The smaller number is : %d", min); int smaller ( int a, int b) { if (a <= b) return(a); else return(b); } This program uses a function to determine the smaller of two integer quantities. The variables are a, b and min. The alternating pairs of printf - scanf statements provide interactive input. The final printf statement is an output statement. The statement min = smaller (a, b) references the function, which is called smaller. This function contains an if - else statement that returns the smaller of the two quantities to the main portion of the program. 2. Determine which of the following are valid identifiers. If invalid, explain why. (a) record1 (e) $tax (h) name_and_address (b) 1record (f) name (i) name-and-address (c) file_3 (g) name and address (j) 123-45 -6789
  • 2. (d) return a.Valid b.An identifier must begin with a letter. c.Valid d.return is a reserved word. e.An identifier must begin with a letter. f.Valid g.Blank spaces are not allowed. h.Valid i.Dash (minus sign) is not allowed. j. An identifier must begin with a letter or an underscore. 3. Write appropriate declarations for each group of variables and arrays. (a) Integer variables: p, q Floating-point variables: x , y , z Character variables: a, b, c (b) Floating-point variables: root1 , root2 Long integer variable: counter Short integer variable: f l a g (a) int p, q; (b) float rootl , root2; float x, y, z; long counter; char a, b , c ; short flag; 4. Explain the purpose of each of the following expressions. (a) a - b (d) a >= b (f) a < ( b / c ) (b) a * (b + c) (e) (a % 5 ) == 0 (g) --a (c) d = a * (b + c) a. Subtract the value of b from the value of a. b. Add the values of b and c, then multiply the sum by the value of a. c. Add the values of b and c and multiply the sum by the value of a. Then assign the result to d. d. Determine whether or not the value of a is greater than or equal to the value of b. The result will be either true or false, represented by the value 1 (true) or 0 (false). e. Divide the value of a by 5, and determine whether or not the remainder is equal to zero. The result will be either true or false. f. Divide the value of b by the value of c, and determine whether or not the value of a is less than the quotient. The result will be either true or false. g. Decrement the value of a; i.e., decrease the value of a by 1. 5. Suppose a, b and c are integer variables that have been assigned the values a = 8, b = 3 and c =- 5. Determine the value of each of the following arithmetic expressions. (a) a + b + c (f) a % c (b) 2 * b + 3 * ( a - c ) (g) a * b / c
  • 3. (c) a / b (h) a * (b / c) (d) a % b (i) (a * c) % b (e) a / c (j) a * (c % b) (a) 6 (f) 3 (b) 45 (g) -4 (c) 2 (h) 0 (because b / c is zero) (d) 2 (i) -1 (e) -1 (j) -16 6. Suppose x, y and z are floating-point variables that have been assigned the values x = 8.8, y = 3.5 and z = -5.2. Determine the value of each of the following arithmetic expressions. (a) x + y + z (b) 2 * y + 3 * ( x - z ) (c) x / y (d) x % y (a) 7.1 (b) 49 (c) 2.51429 (d) The remainder operation is not defined for floating-point operands 7. A C program contains the following declarations and initial assignments: int i= 8, j = 5, k; float x = 0.005, y = -0.01, z; char a, b, c = ' c ' , d = ‘d ' ; Determine the value of each of the following assignment expressions. Use the values originally assigned to the variables for each expression. (a) k = (i + j ) (i) z = k = x (b) z = (x + y) (j) k = z = x (c) i = j (k) i += 2 (d) k = (x + y) (l) y -= x (e) k = c (m) x *= 2 (f) z = i / j (n) i /= j (g) a = b = d (o) i %= j (h) i= j = 1.1 (p) i+= ( j - 2) (a) k= 13 (i) k = 0, z = 0.0 (b) z = -0.005 (j) z = 0.005, k = 0 [compare with (i) above] (c) i=5 (k) i= 10 (d) k=0 (l) y = -0.015 (e) k = 99 (m) x = 0.010 (f) z = 1.0 (n) i=l
  • 4. (g) b = 100, a = 100 (Note (o) i=3 that 100 is the encoded value for 'd’ in the ASCII character set.) (h) j = l , i = l (p) i= 11 8. A C program contains the following declarations and initial assignments: int i = 8, j = 5; double x = 0.005, y = -0.01; char c = 'c’ , d = ‘d'; Determine the value of each of the following expressions, which involve the use of library functions. (a) abs(i - 2 * j ) (b) fabs(x + y) (c) ceil(x) (d) ceil(x + y) (a) 2 (i) 0.005 (e) floor(x) (b) 0.005 (j) 0.011180 (f) floor(x + y) (c) 1.0 (k) 0.014999 (g) exp(x) (d) 0.0 (l) 1.002472 (h) log(x) (e) 0.0 (i) log(exp(x)) (f) -1.0 (j) sqrt(x*x + y*y) (g) 1.005013 (k) sin(x - y) (h) -5.298317 (l) sqrt(sin(x) + cos(y)) 9. A C program contains the following statements: #include <stdio.h> char a, b, c; (a) Write appropriate getchar statements that will allow values for a, b and c to be entered into the computer. (b) Write appropriate putchar statements that will allow the current values of a, b and c to be written out of the computer (i.e., to be displayed). (a) a = getchar(); (b) putchar (a) ; b = getchar(); putchar(b); c = getchar(); putchar(c); 10. Solve Prob. 9 using a single scanf function and a single print f function rather than the getchar and putchar statements. (a) scanf ( "%c%c%c", &a, &b, (b) printf(n%c%c%c”, a, b, c); &c) ; or printf ( " % c %c %c”, a, b, or scanf ("%c %c %c", &a, c); &b, &c); 11. A C program contains the following statements: #include <stdio.h> int i, j, k;
  • 5. Write a printf function for each of the following groups of variables or expressions. Assume all variables represent decimal integers. (a) i, j and k (b) (i + j), (i - k) (c) sqrt(i + j),abs(i - k) (a) printf (“%d %d %d”, i,j, k); (b) printf ( "%d %d", (i+ j ) , ( i - k)); (c) printf ( "% f %d", sqrt(i + j) , abs(i - k)); 12. A C program contains the following statements. #include <stdio.h> char text [ 80]; Write a printf function that will allow the contents of text to be displayed in the following ways. (a) Entirely on one line. (b) Only the first eight characters. (c) The first eight characters, preceded by five blanks. (d) The first eight characters, followed by five blanks. (a) printf ( “ %s" , text ) ; (b) printf("%.8s", text ) ; (c) printf ( "%13.8s", text ) ; (d) printf ( "%-13.8s”, text ) ; 13. A C program contains the following array declaration. char text[80]; Suppose that the following string has been assigned to text. Programming with C can be a challenging creative activity. Show the output resulting from the following printf statements. (a) printf ( "%s", text ) ; (d) printf ( "%18.7s", text ) ; (b) printf ("%18s", text ) ; (e) printf ( " % -18.7s " , text ) ; (c) printf ( “%.18s", text ) ; (a) Programming with C can be a challenging creative activity. (b) Programming with C can be a challenging creative activity. (c) Programming with C (d) Program (e) Program 14. Write a switch statement that will examine the value of a char-type variable called color and print one of the following messages, depending on the character assigned to color. (a) RED, if either r or R is assigned to color, (b) GREEN, if either g or G is assigned to color, (c) BLUE, if either b or B is assigned to color, (d) BLACK, if color is assigned any other character
  • 6. (a) switch (color) { case ‘r': case ' R ' : printf ( “RED") ; break; (b) case ' g ‘ : case ' G ' : printf ("GREEN” ) ; break; (c) case ' b ' : case ' B ' : printf ( ''BLUE"); break; (d) default : printf ( “BLACK") ; break; 15. Write an appropriate control structure that will examine the value of a floating-point variable called temp and print one of the following messages, depending on the value assigned to temp. (a) ICE, if the value of temp is less than 0. (b) WATER, if the value of temp lies between 0and 100. (c) STEAM, if the value of temp exceeds 100. Can a switch statement be used in this instance? if (temp < 0.) printf ( " ICE"); else if (temp >= 0. && temp <= 100.) printf ( "WATER') ; else printf("STEAM") ; A switch statement cannot be used because: (a) The tests involve floating-point quantities rather than integer quantities. (b) The tests involve ranges of values rather than exact values. 16. Describe the output that will be generated by each of the following C program. #include <stdio. h> main ( ) { int i = 0, x = 0; while(i<20){ 0 5 15 30 if (i % 5 == 0) { x += i; x = 30 printf("%d ", x); } ++i ; } printf('nx = %d", x); } 17. What is meant by a function call? From what parts of a program can a function be called?
  • 7. accessing a function by specifying its name, followed by a list g arguments enclosed in parentheses and separated by commas. If the function call does not require any arguments, an empty pair of parentheses must follow the name of the function. . Function call can be a part of a simple expression (such as an assignment statement) or may be one of the operands (3+5, 3 and 5are operands) within more complex expression or directly from printf. 18. Can a function be called from more than one place within a program? Yes 19. When a function is accessed, must the names of the actual arguments agree with the names of the arguments in the corresponding function prototype? No 20. Each of the following is the first line of a function definition. Explain the meaning of each. (a) float f ( float a, float b) (c) void f ( int a) (b) long f (long a) (d) char f (void) (a) f accepts two floating-point arguments and returns a floating-point value. (b) f accepts a long integer and returns a long integer. (c) f accepts an integer and returns nothing. (d) f accepts nothing but returns a character. 21. Write an appropriate function call (function access) for each of the following functions. (a) float formula(f1oat x) (b) void display ( int a, int b) { { float y; int c; y = 3 * x - 1; c = sqrt(a * a + b * b); return ( y ) ; printf ( " c = % i n " , c ) ; } } (a) y = formula(x); (b) display(a, b); 22. Write the first line of the function definition, including the formal argument declarations, for each of the situations described below. (a) A function called sample generates and returns an integer quantity. (b) A function called root accepts two integer arguments and returns a floating-point result. (c) A function called convert accepts a character and returns another character. (d) A function called transfer accepts a long integer and returns a character. (e) A function called inverse accepts a character and returns a long integer. (f) A function called process accepts an integer and two floating-point quantities (in that order), and returns a double-precision quantity. (a) int sample(void) (b) float root ( int a , int b) (c) char convert (char c) (d) char transfer(1ong i ) (e) long inverse(char c) (f) double process(int i, float a, float b)
  • 8. 23. Explain the meaning of each of the following declarations. (a) int *px; (b) float a = -0.167; float *pa = &a; (a) px is a pointer to an integer quantity. (b) a is a floating-point variable whose initial value is -0.167; pa is a pointer to a floating-point quantity; the address of a is assigned to pa as an initial value. 24. A C program contains the following statements. float a = 0.001, b = 0.003; float c, *pa, *pb; pa = &a; *pa = 2 * a; pb = &b; c = 3 * (*pb - *pa); Suppose each floating-point number occupies 4 bytes of memory. If the value assigned to a begins at (hexadecimal) address 1130, the value assigned to b begins at address 1134, and the value assigned to c begins at 1138, then (a) What value is assigned to &a? (b) What value is assigned to &b? (c) What value is assigned to &c? (d) What value is assigned to pa? (e) What value is represented by *pa? (f) What value is represented by &( *pa)? (g) What value is assigned to pb? (h) What value is represented by *pb? (i) What value is assigned to c? (a) 1130 (b) 1134 (c) 1138 (d) 1130 (e) 0.002 (f) &(*pa) = pa = 1130 (g) 1134 (h) 0.003 (i) 0.003 Multiple selection questions 1. Which of the following is the correct variable definition? a. 123_name b. &name c. Name_1 d. #name@
  • 9. 2. Which of the following is not a data type in C? a. Integer b. Double c. data d. unsigned 3. How would you assign the value 3.14 to a variable called pi? a. int pi; b. unsigned pi; pi=3.14; pi=3.14; c. string pi; d. float pi; pi=3.14; pi=3.14; 4. A common mistake for new students is reversing the assignment statement. Suppose you want to assign the value stored in the variable "pi" to another variable, say "pi2": i. What is the correct statement? a. pi2 = pi; b. pi = pi2; ii. What is the reverse? Is this a valid C statement (even if it gives incorrect results)? a. pi2 = pi; is a valid C statement if pi b. pi = pi2; is a valid C statement if is not a constant. pi is not a constant. iii. What if you wanted to assign a constant value (like 3.1415) to "pi2": What would the correct statement look like? Would the reverse be a valid or invalid C statement? a. pi2 = 3.1415; b. 3.1415 = pi2; The reverse is not a valid The reverse is a valid statement. statement. 5. scanf() is a very powerful function. What does it do? a. scanf echos characters from the standard input, interprets them according to the specification in format, and stores the results through the remaining arguments. b. scanf displays characters from the standard input, interprets them according to the specification in format, and stores the results through the remaining arguments. c. scanf is the input analog of printf, providing many of the same conversion facilities in the opposite direction. d. scanf is the output analog of printf, providing many of the same conversion facilities in the opposite direction. 6. Write the scanf() function call that will read into the variable "var": i. a float ii. an int iii. a double
  • 10. a. scanf("%f",&var); b. scanf("%f",&var); scanf("%d",&var); scanf("%d",&var); scanf("%d", &var); scanf("%lf", &var); c. scanf("%f",&var); d. scanf("%f",&var); scanf("%i",&var); scanf("%d",&var); scanf("%u", &var); scanf("%s", &var); 7. What is the output for the following program? #include<stdio.h> main() { int a,b; float c,d; a = 18; b = a / 2; printf("%dn",b); printf("%2dn",b); printf("%04dn",b); c = 18.3; d = c / 3; printf("%5.3fn",d); printf(":%-15.10s:n", "Are you ready?!"); getch(); } a. 9 b. 9 9 9 0009 0009 6.100 6.100 :Are you re : :Are you re : c. 9 d. 9 9 9 0009 0009 6.100 6.10 :Are you read : :Are you re :
  • 11. 8. Which of the following flowchart is best suitable for multiple choices problem? (a) While, for, do-while (b) If – else selection (c) Case structures
  • 12. 9. Write a complete program that outputs a right isosceles (with (at least) two equal sides) triangle of height and width n, so n = 6 would look like * ** *** **** ***** ****** The triangle function is given as below: void isosceles(int n) { int x,y; for (y= 0; y < n; y++) { for (x= 0; x <= y; x++) putchar('*'); putchar('n'); } } a. #include<stdio.h> b. #include<stdio.h> #include<conio.h> #include<conio.h> void isosceles(int n); void isosceles(int n) { main() int x,y; { for (y= 0; y < n; y++) int n; { printf("n insert no of rows of for (x= 0; x <= y; x++) your triangle:"); putchar('*'); scanf("%d",&n); putchar('n'); isosceles(n); } } getch(); main() } { void isosceles(int n) int n; { printf("n insert no of rows of your int x,y; triangle:"); for (y= 0; y < n; y++) scanf("%d",&n); { for (x= 0; x <= y; x++) getch(); putchar('*'); } putchar('n'); } } c. #include<stdio.h> d. #include<stdio.h> #include<conio.h> #include<conio.h>
  • 13. void isosceles(int n); void isosceles(int n) { main() int x,y; { for (y= 0; y < n; y++) int n; { printf("n insert no of rows of your for (x= 0; x <= y; x++) triangle:"); putchar('*'); scanf("%d",&n); putchar('n'); } getch(); } } void isosceles(int n) main() { { int x,y; int n; for (y= 0; y < n; y++) printf("n insert no of rows of your { triangle:"); for (x= 0; x <= y; x++) isosceles(n); putchar('*'); putchar('n'); getch(); } } } 10. What is the correct output of the following code? #include <stdio.h> #include <conio.h> a. Please input two numbers to be multiplied: 1 int mult ( int x, int y ); 5 The product of your two int main() { numbers is 5 int x; int y; b. Please input two numbers to be multiplied: 1 printf( "Please input two 5 numbers to be multiplied: " ); scanf( "%d", &x ); The product of your two scanf( "%d", &y ); numbers is 15 printf( "The product of your two numbers is %dn", mult( x, c. The product of your two y ) ); getch(); numbers is 15 } d. The product of your two int mult (int x, int y) numbers is 5 { return x * y; }
  • 14. 11. How many functions are there (including main function) in the coding? #include<stdio.h> #include<conio.h> void myFunction(); int add(int, int); int main() { myFunction(); printf("nn%d",add(10,15)); getch(); } void myFunction() { printf("This is inside function :D"); } int add(int a, int b) { return a+b; } a. 1 b. 2 c. 3 d. 4 12. What is the output of the program in Ques.11? a. This is inside function :D b. 25 c. 25 This is inside function :D d. This is inside function :D 25 13. Below are the advantages of using functions except? a. It makes possible top down modular programming. In this style of programming, the high level logic of the overall problem is solved first while the details of each lower level functions is addressed later.
  • 15. b. The length of the source program can be reduced by using functions at appropriate places. c. It becomes complicated to locate and separate a faulty function for further study. d. A function may be used later by many other programs this means that a c programmer can use function written by others, instead of starting over from scratch. 14. The correct output for the following function is: #include<stdio.h> #include<conio.h> void add(int x,int y) { int result; result = x+y; printf("Sum of %d and %d is %d.nn",x,y,result); } main() { add(10,15); add(55,64); add(168,325); getch(); } a. Sum of 10 and 15 is 25. Sum of 55 and 64 is 119. Sum of 168 and 325 is 493. b. Sum of 10 and 15 is 25. Sum of 168 and 325 is 493. Sum of 55 and 64 is 119. c. Sum of 20 and 15 is 25. Sum of 65 and 64 is 119. Sum of 168 and 325 is 493. d. Sum of 55 and 64 is 117. Sum of 10 and 15 is 25. Sum of 168 and 325 is 493.