1 of 63

UNIT 1

Fundamentals of Computers & Problem Solving in C

2 of 63

3 of 63

Basics of Computers – Introduction

4 of 63

Input-Process-Output Model�

  • Basics of Computers - Classification

  • Desktop
  • Laptop
  • Tablet
  • Server
  • Mainframe
  • Supercomputer
  • History of Computers
  • Abacus
  • Structure
  • Napier’s Bones
  • Pascaline
  • Stepped Reckoner or Leibniz wheel
  • Analytical Engine
  • Tabulating Machine
  • Differential Analyzer

Introduction

  • Input-Process-Output Model
  • Input Unit
  • Output Unit
  • Control Unit
  • Arithmetic Logic Unit
  • Memory
  • Characteristics of Computer
  • Speed
  • Accuracy
  • Reliability
  • Versatility
  • Storage Capacity

5 of 63

Generations of Computers�

  • First Generation Computers
  • Second Generation Computers
  • Third Generation Computers
  • Fourth Generation Computers
  • Fifth Generation Computers

6 of 63

Anatomy Of A Computer�

7 of 63

8 of 63

9 of 63

10 of 63

11 of 63

UNIT 2

Overview of C

12 of 63

Character Set in C�

C TOKEN

Introduction:

  • Character Set is a collection of permissible characters that can be used in a variety of contexts by the program. In this article, we covered the history of Character encodings.
  • Types of Character Set
  • Source Character Set (SCS)
  • Execution Character Set (ECS)

13 of 63

14 of 63

15 of 63

VARIABLES�

Declaring (Creating) Variables

Syntax

type variableName = value;

Example

Create a variable called myNum of type int and assign the value 15 to it:

int myNum = 15;

16 of 63

DATA TYPES

17 of 63

OPERATORS

18 of 63

ARITHMETIC EXPRESSIONS�

19 of 63

EVALUATION OF EXPRESSION�

20 of 63

PRECEDENCE OF ARITHMETIC OPERATORS�

21 of 63

22 of 63

23 of 63

24 of 63

25 of 63

FORMATTED INPUT AND OUTPUT.

26 of 63

UNIT:3

Decision Making , Looping and Arrays

27 of 63

IF

28 of 63

IF….ELSE

29 of 63

NESTING OF IF …ELSE STATEMENTS

30 of 63

ELSE IF LADDER

31 of 63

#include<stdio.h>

void main ()

{

   int a,b,c,d;

   printf("Enter the values of a,b,c,d: ");  

 scanf("%d%d%d%d",&a,&b,&c,&d);  

 if(a>b && a>c && a>d)

{      

printf("%d is the largest",a);  

 }

else if(b>c && b>a && b>d)

{      

printf("%d is the largest",b);  

 }

else if(c>d && c>a && c>b)

{      

printf("%d is the largest",c);  

 }

Else

{      

printf("%d is the largest",d);  

 }

}

Output

You will see the following output −

Run 1:Enter the values of a,b,c,d: 2 4 6 8 8 is the largest Run 2: Enter the values of a,b,c,d: 23 12 56 23 56 is the largest

32 of 63

Switch Statement in C�

#include <stdio.h>

int main() {

int choice;

printf("Enter a number (1-3): ");

scanf("%d", &choice);

switch (choice) {

case 1:

printf("You entered 1.\n");

break;

case 2:

printf("You entered 2.\n");

break;

case 3:

printf("You entered 3.\n");

break;

default:

printf("Invalid number.\n");

break;

}

return 0;

}

Output:

Enter a number (1-3): 2 You entered 2.

33 of 63

The ?: Operator

Syntax of Conditional/Ternary Operator in C

  • The conditional operator can be in the form

variable = Expression1 ? Expression2 : Expression3;

Or the syntax can also be in this form

variable = (condition) ? Expression2 : Expression3;

34 of 63

THE GOTO STATEMENT

  • Syntax:
  • label:   
  • //some part of the code;   
  • goto label;  

  1. #include <stdio.h>  
  2. int main()   
  3. {  
  4.   int num,i=1;   
  5.   printf("Enter the number whose table you want to print?");   
  6.   scanf("%d",&num);  
  7.   table:   
  8.   printf("%d x %d = %d\n",num,i,num*i);  
  9.   i++;  
  10.   if(i<=10)  
  11.   goto table;    
  12. }  

35 of 63

Decision Making and Looping

The while statement

Flowchart of while loop in C

     

36 of 63

While loop example program

  1. #include<stdio.h>  
  2. int main(){    
  3. int i=1,number=0,b=9;    
  4. printf("Enter a number: ");    
  5. scanf("%d",&number);    
  6. while(i<=10){    
  7. printf("%d \n",(number*i));    
  8. i++;    
  9. }    
  10. return 0;  
  11. }   

Output

Enter a number: 50 50 100 150 200 250 300 350 400 450 500

37 of 63

THE DO STATEMENT

38 of 63

  1. #include<stdio.h>  
  2. #include<stdlib.h>  
  3. void main ()  
  4. {  
  5.     char c;  
  6.     int choice, dummy;    
  7.     do{  
  8.     printf("\n1. Print Hello\n2. Print Java point\n3. Exit\n");  
  9.     scanf("%d",&choice);  
  10.     switch(choice)  
  11.     {  
  12.         case 1 :   
  13.         printf("Hello");   
  14.         break;  
  15.         case 2:    
  16.         printf("Java point");  
  17.         break;  
  18.         case 3:  
  19.         exit(0);   
  20.         break;  
  21.         default:   
  22.         printf("please enter valid choice");      
  23.     }  
  24.     printf("do you want to enter more?");   
  25.     scanf("%d",&dummy);  
  26.     scanf("%c",&c);  
  27.     }while(c=='y');  
  28. }  

Output

1. Print Hello 2. Print Java point 3. Exit 1 Hello do you want to enter more? y 1. Print Hello 2. Print Javatpoint 3. Exit 2 Javatpoint do you want to enter more? n

39 of 63

The for statement

40 of 63

syntax

41 of 63

Types of Jump Statements in C

  • There are 4 types of jump statements in C:

  • break
  • continue
  • goto
  • return

Syntax of break in C

break;

#include <stdio.h>

int main()

{

int i;

// for loop

for (i = 1; i <= 10; i++) {

// when i = 6, the loop should end

if (i == 6) {

break;

}

printf("%d ", i);

}

printf("Loop exited.\n");

return 0;

}

Output

1 2 3 4 5 Loop exited.

42 of 63

Arrays:

43 of 63

// C Program to print Array

// of strings

#include <stdio.h>

// Driver code

int main()

{

char arr[3][10] = {"Geek",

"Geeks", "Geekfor"};

printf("String array Elements are:\n");

for (int i = 0; i < 3; i++)

{

printf("%s\n", arr[i]);

}

return 0;

}

44 of 63

Unit:4

45 of 63

46 of 63

47 of 63

48 of 63

49 of 63

50 of 63

Nesting of�Functions

#include <stdio.h>

int main(void)

{

printf("Main");

int fun()

{

printf("fun");

// defining view() function inside fun() function

int view()

{

printf("view");

}

return 1;

}

view()

51 of 63

Recursion

52 of 63

53 of 63

54 of 63

The Scope,Visibility and Lifetime of�Variables

55 of 63

Structures

56 of 63

// C program to illustrate the use of structures

#include <stdio.h>

// declaring structure with name str1

struct str1 {

int i;

char c;

float f;

char s[30];

};

// declaring structure with name str2

struct str2 {

int ii;

char cc;

float ff;

} var; // variable declaration with structure template

57 of 63

Union

58 of 63

59 of 63

Unit:5

Pointers: Introduction

60 of 63

61 of 63

62 of 63

63 of 63

conclusion