SlideShare a Scribd company logo
1 of 4
ICS103 Programming in C

  Lecture 8: Exercises




                          1
Exercise 1
• What is the output of the following program.
   int f1(int a, int b){
      a = 2 * m2(a);
      return a + b;
   }

   int f2(int a){
      return a % 2;
   }

   int main(){
     int a = 10, b = 20;
     printf(“%d”, f1(a, 2));
     b = f2(b / a);
     printf(“a = %d b = %d“, a, b);
     return 0;
   }
                                                 2
Exercise 2
• What is the output of the following program.
   int main(){
     int a = 10, b = 20;
     a = f1(a, b);
     b = f1(b, a);
     printf(“a = %d b = %d“, a, b);
     return 0;
   }

   int f1(int a, int b){
      return a * a + 2 * b;
   }




                                                 3
Exercise 3
• What is the output of the following program.
   int main(){
     int a, b;
     printf(“Enter      a b”);
     scanf(%d %d”,      &a, &b);
     if(xor(a, b))
       printf(“a =      %d “, a);
     else
       printf(“b =      %d “, b);
     return 0;
   }

   int xor(int    a, int b){
      if(a < 0    && b < 0 || a > 0 && b > 0)
        return    0;
      else
        return    1;
   }
                                                 4

More Related Content

What's hot

Lecture 8 increment_and_decrement_operators
Lecture 8 increment_and_decrement_operatorsLecture 8 increment_and_decrement_operators
Lecture 8 increment_and_decrement_operatorseShikshak
 
Method C# - Lec8 (Workshop on C# Programming: Learn to Build)
Method C# - Lec8 (Workshop on C# Programming: Learn to Build)Method C# - Lec8 (Workshop on C# Programming: Learn to Build)
Method C# - Lec8 (Workshop on C# Programming: Learn to Build)Jannat Ruma
 
C program to add two numbers
C program to add two numbers C program to add two numbers
C program to add two numbers mohdshanu
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7alish sha
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7Rumman Ansari
 
Labsheet2 stud
Labsheet2 studLabsheet2 stud
Labsheet2 studrohassanie
 
Ffffffffffff
FfffffffffffFfffffffffff
Ffffffffffffmohdshanu
 
Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructionsLearn By Watch
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8alish sha
 
Testing lecture after lec 4
Testing lecture after lec 4Testing lecture after lec 4
Testing lecture after lec 4emailharmeet
 
C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloadingmohamed sikander
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++Neeru Mittal
 
C programming pointer
C  programming pointerC  programming pointer
C programming pointerargusacademy
 
C Programming Language Part 9
C Programming Language Part 9C Programming Language Part 9
C Programming Language Part 9Rumman Ansari
 

What's hot (20)

Lab 2
Lab 2Lab 2
Lab 2
 
Lecture 8 increment_and_decrement_operators
Lecture 8 increment_and_decrement_operatorsLecture 8 increment_and_decrement_operators
Lecture 8 increment_and_decrement_operators
 
CSE240 Pointers
CSE240 PointersCSE240 Pointers
CSE240 Pointers
 
week-10x
week-10xweek-10x
week-10x
 
week-1x
week-1xweek-1x
week-1x
 
Method C# - Lec8 (Workshop on C# Programming: Learn to Build)
Method C# - Lec8 (Workshop on C# Programming: Learn to Build)Method C# - Lec8 (Workshop on C# Programming: Learn to Build)
Method C# - Lec8 (Workshop on C# Programming: Learn to Build)
 
C program to add two numbers
C program to add two numbers C program to add two numbers
C program to add two numbers
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
 
6. function
6. function6. function
6. function
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
 
Labsheet2 stud
Labsheet2 studLabsheet2 stud
Labsheet2 stud
 
Ffffffffffff
FfffffffffffFfffffffffff
Ffffffffffff
 
week-18x
week-18xweek-18x
week-18x
 
Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructions
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
 
Testing lecture after lec 4
Testing lecture after lec 4Testing lecture after lec 4
Testing lecture after lec 4
 
C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloading
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
 
C programming pointer
C  programming pointerC  programming pointer
C programming pointer
 
C Programming Language Part 9
C Programming Language Part 9C Programming Language Part 9
C Programming Language Part 9
 

Similar to Lect08 exercises

Similar to Lect08 exercises (20)

C exam
C examC exam
C exam
 
lets play with "c"..!!! :):)
lets play with "c"..!!! :):)lets play with "c"..!!! :):)
lets play with "c"..!!! :):)
 
C questions
C questionsC questions
C questions
 
Quiz 10 cp_sol
Quiz 10 cp_solQuiz 10 cp_sol
Quiz 10 cp_sol
 
operators.ppt
operators.pptoperators.ppt
operators.ppt
 
Technical c
Technical cTechnical c
Technical c
 
Technical questions
Technical questionsTechnical questions
Technical questions
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
(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
 
pointer.ppt hfkogfhkigfvjjgdsyhhgfdfghjb
pointer.ppt hfkogfhkigfvjjgdsyhhgfdfghjbpointer.ppt hfkogfhkigfvjjgdsyhhgfdfghjb
pointer.ppt hfkogfhkigfvjjgdsyhhgfdfghjb
 
pointer.ppt hfkogfhkigfvjjgdsyhhgfdfghjb
pointer.ppt hfkogfhkigfvjjgdsyhhgfdfghjbpointer.ppt hfkogfhkigfvjjgdsyhhgfdfghjb
pointer.ppt hfkogfhkigfvjjgdsyhhgfdfghjb
 
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
 
Oops Quiz
Oops QuizOops Quiz
Oops Quiz
 
c interview progs.pdf
c interview progs.pdfc interview progs.pdf
c interview progs.pdf
 
Labsheet2
Labsheet2Labsheet2
Labsheet2
 
Embedded C - Day 2
Embedded C - Day 2Embedded C - Day 2
Embedded C - Day 2
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
 
Understanding storage class using nm
Understanding storage class using nmUnderstanding storage class using nm
Understanding storage class using nm
 

Lect08 exercises

  • 1. ICS103 Programming in C Lecture 8: Exercises 1
  • 2. Exercise 1 • What is the output of the following program. int f1(int a, int b){ a = 2 * m2(a); return a + b; } int f2(int a){ return a % 2; } int main(){ int a = 10, b = 20; printf(“%d”, f1(a, 2)); b = f2(b / a); printf(“a = %d b = %d“, a, b); return 0; } 2
  • 3. Exercise 2 • What is the output of the following program. int main(){ int a = 10, b = 20; a = f1(a, b); b = f1(b, a); printf(“a = %d b = %d“, a, b); return 0; } int f1(int a, int b){ return a * a + 2 * b; } 3
  • 4. Exercise 3 • What is the output of the following program. int main(){ int a, b; printf(“Enter a b”); scanf(%d %d”, &a, &b); if(xor(a, b)) printf(“a = %d “, a); else printf(“b = %d “, b); return 0; } int xor(int a, int b){ if(a < 0 && b < 0 || a > 0 && b > 0) return 0; else return 1; } 4