UNIT 1
Fundamentals of Computers & Problem Solving in C
Basics of Computers – Introduction
Input-Process-Output Model�
Introduction
Generations of Computers�
Anatomy Of A Computer�
UNIT 2
Overview of C
Character Set in C�
C TOKEN
Introduction:
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;
DATA TYPES �
OPERATORS
ARITHMETIC EXPRESSIONS�
EVALUATION OF EXPRESSION�
PRECEDENCE OF ARITHMETIC OPERATORS�
FORMATTED INPUT AND OUTPUT.
UNIT:3
Decision Making , Looping and Arrays
IF
IF….ELSE
NESTING OF IF …ELSE STATEMENTS
ELSE IF LADDER
#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
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.
The ?: Operator
Syntax of Conditional/Ternary Operator in C
variable = Expression1 ? Expression2 : Expression3;
Or the syntax can also be in this form
variable = (condition) ? Expression2 : Expression3;
THE GOTO STATEMENT
Decision Making and Looping
The while statement
Flowchart of while loop in C
While loop example program
Output
Enter a number: 50 50 100 150 200 250 300 350 400 450 500
THE DO STATEMENT
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
The for statement
syntax
Types of Jump Statements in C
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.
Arrays:
// 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;
}
Unit:4
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()
Recursion
The Scope,Visibility and Lifetime of�Variables
Structures
// 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
Union
Unit:5
Pointers: Introduction
conclusion