Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
A
S
D
L
;
Computer system
Monitor
CPU
Monitor
CPU
memory
Monitor Hard disk
processor
CPU
Sum is
void main()
{
int a = 4,b =7 , c; 4 a
c = a + b; 7 b
printf(“ sum is %d” ,c);
} 11 c
Sum is 11
void main()
{
47
4
0 a
int a = 4,b = 7, c;
c = a + b; 11
70 b
printf(“ %d + %d is %d “,a,b,c);
11 c
} junk
4 + 7 = 11
What is programming?
#include<stdio.h>
void main()//a must for any C program to work
{
printf(“Let Us C”);
}
See Programming in C
#include<stdio.h>
void main()//see the function braces
{
printf(“Let Us C”);
}
See Programming in C
#include<stdio.h>
void main()//see the function braces
// there is a space between void and main
// main can not be capital! ie. C is case sensitive
{
printf(“Let Us C”);
}
See Programming in C
#include<stdio.h>
void main()//function header
{
printf(“Let Us C”);
}
See Programming in C
#include<stdio.h>
void main()//function header
{
printf(“Let Us C”);
}
If there is a head, there shall be a
body after/below the head
See Programming in C
#include<stdio.h>
void main()//function header
{// body begins
printf(“Let Us C”);
}// body ends
If there is a head, there shall be a
body after/below the head
See Programming in C
#include<stdio.h>
void main()//function header
{
printf(“Let Us C”);// end of an instruction
}
Every program should have this DISSECTION of
function and only one main a basic C
function. No capital M please program
Function Function braces, simple braces,
body ellipse. This is to hold or receive
begins parameters or arguments.
main() Presently it is holding nothing
{
Function printf(“Welcome to see the sea of C”);
body }
ends printf function
takes/holds necessarily End of an
Only one one argument which is a instruction is
instruction or
statement
string. Starting and signaled by ;
ending by ” ”
#include<stdio.h> printf should have a
prototype ?
main()
{
printf(“\n \tWelcome to see the sea of C”) ;
}}
#include<stdio.h>
void main()
{
printf(“Let Us C”);
}
See Programming in C
Let Us C
#include<stdio.h>
void main()
{
printf(“Let Us C”);
}
See Programming in C
#include<stdio.h>
void main()
{
printf(“Let Us \nC”);
}
See Programming in C
Let Us
#include<stdio.h>
void main() C
{
printf(“Let Us \nC”);
}
See Programming in C
#include<stdio.h>
void main()
{
printf(“Le\tt Us C”);
}
See Programming in C
Le t Us C
#include<stdio.h>
void main()
{
printf(“Le\tt Us C”);
}
See Programming in C
#include<stdio.h>
void main()
{
printf(“Let Us C\bK”);
}
See Programming in C
Let Us K
#include<stdio.h>
void main()
{
printf(“Let Us C\bK”);
}
See Programming in C
#include<stdio.h>
void main()
{
printf(“Let Us C\rG”);
}
See Programming in C
Get Us C
#include<stdio.h>
void main()
{
printf(“Let Us C\rG”);
}
See Programming in C
#include<stdio.h>
void main()
{
printf(“Let Us C\a”);
}
See Programming in C
Let Us C
#include<stdio.h>
void main()
{
printf(“Let Us C\a”);
}
See Programming in C: Use of Variables
#include<stdio.h>
void main()
{
a = 5;
printf(“a = a”);
}
See Programming in C: Use of Variables
#include<stdio.h>
void main()
{
a = 5;
printf(“a = a”);
}
#include<stdio.h>
void main()
{
int a; //integer: used for counting
printf(“a = a”);
}
#include<stdio.h> a=a
void main()
{
int a;
printf(“a = a”);
}
Data type followed by The value of a is
variable name 6785
#include<stdio.h> Declaration of
a variable
main()
{
int a;
printf(“\n The value of a is %d “,a);
#include<stdio.h>
void main()
{
int a; //variable declaration
a = 5; // initialisatioin
printf(“a = %d”,a);
}
See Programming in C: Use of Variables
#include<stdio.h> a=5
void main()
{
int a;
a = 5;
printf(“a = %d”, a);
}
The value of a is
6
#include<stdio.h> Declaration &
main() Initialization of a
{ variable
int a = 6;
printf(“\n The value of a is %d “,a);
}
See Programming in C: Use of Variables
#include<stdio.h> 5+3= 8
void main()
{
int a=5,b=3,c;
c = a + b;
printf(“%d + %d = %d”,a,b,c);
}
See Programming in C: Use of Variables
#include<stdio.h> 5+3= 8
void main()
{
int a=5,b=3,c;
c = a + b;
printf(“%d + %d = %d”,a,b,c);
}
Place holders in printf statement and the
variables listed after the string sit in the
place holders in the same order
The product 6 * 5 = 30
#include<stdio.h>
main()
{ format specifier
int a,b; or place holder
a = 6;
b= 5;
printf(“\n The product %d * %d = %d “,a, b , a*b);
}
#include<stdio.h>
The prod of 6 and
5 is 30
main()
{
int a=6,b=5;
printf(“\n The prod of %d and %d is %d = %d”, .
a, b , a*b); Variable declaration and
initialization can be done
} together for multiple vars
#include<stdio.h>
The prod of 6 and
5 is 30
main()
{
int a=6,b=5;
printf(“\n The prod of %d and %d is %d = %d”, .
a, b , a*b); Variable declaration and
initialization can be done
} together for multiple vars
But what is the big deal if we know the values in
advance? Hard coded values! Why not soft code?
Accept from KB during the run time?
See Programming in C: accepting of Variables
#include<stdio.h>
void main()
{
int a,b;
printf(“enter value of a”);
scanf(“%d”,&a);
b = 2 * a;
printf(“%d x 2 = %d”,a,b);
}
See Programming in C: accepting of Variables
#include<stdio.h>
void main()
{
int a,b;
printf(“enter value of a”);
scanf(“%d”,&a);
b = 2 * a; 627 a
printf(“%d x 2 = %d”,a,b); 7218 b
}
In memory
See Programming in C: accepting of Variables
2 36
9625 sq #include<stdio.h>
main()
{
int a,sq;
printf(“\n Enter the value of a to find square ”);
scanf(“%d”,&a);
sq= a * a;
printf(“\n The square of %d is %d “,a, sq);
6
}
Common error messages
Statement missing
check the semicolon in the previous line
Compound statement missing
check whether the closing curly brace is missing
Declaration not allowed
check whether the opening curly brace is missing
Un-terminated string or character constant
check whether the string which is started is ended or
not: any closing double quote missing
Undefined symbol ‘x’
check whether the variable is declared or not
Undefined symbol ‘xyz’,’pqr’,’apwzyd’….
Check whether a string starting is missing or not
L value expected
check whether some constant is being modified
Connot covert int * to int
check whether an integer pointer value is being
assigned to an integer variable
Too few parameters in the function call
check the shortage of parameters in the calling of a
function, whereas the function definition or prototype
has more parameters
Too many parameters in the function call
check the additional parameters in the calling of a
function, whereas the function definition or prototype
has lesser parameters
The sum is
void main() 47
4
0 num
{
sum
int num = 47,sum = 0, ld; 11
11
70
2 9625
81
625
36 #include<stdio.h>
sq main()
3 5681
2
3
4
1 {
int a,sq,count;
count for(count=1,count<=3;count++)
{
printf(“\n Enter the value to square ”);
scanf(“%d”,&a);
sq= a * a;
printf(“\n The square of %d is %d “,a, sq);
925
6
}
}
In the
Enter the value of a to find square 6
9
1 memory The square of 625 is is
36 62581
5681
a #include<stdio.h>
main()
2 9625
81
625
36 {
sq int a,sq,count;
3 5681
2
3
4
1 for(count=1,icount<=3;count++)
count {
printf(“\n Enter the value to square ”);
scanf(“%d”,&a);
sq= a * a;
printf(“\n The square of %d is %d “,a, sq);
925
6 }
}
Problems to be done
Swapping of two variables
Swapping/rotation among n variables
If statement syntax. Only one side
check pass/even
absolute value
If else statement syntax. both sides
pass or fail/odd or even
biggest among two vars
sort 2 variables
senior/junior
last digit is odd/even
last but one digit odd/even
divisible by 7 or not
Nested if else
3 var biggest
3 var sort
grade s, a, b,c…
incentive upto and then on…
special pass criterion
roots of a quadratic equation
sides of a triangle
For loop
With serial numbers
The dynamics of for loop
Printing all the numbers from 1 to 50
Summing up all numbers from 1 to 50
Accepting variables n times and processing them
21 matchstick game
Printing a single star
Printing a line of stars
Printing the digits of a number
Summing up the digits of a number
Convert a number to binary
Check whether a number is palindrome
Check whether a number is sliding down or climbing up
Check whether a given number is prime or not
Check whether a number is Armstrong
Perfect number
Single digit sum number or not
Cup number
Grove number
Platau number
Mountain number
Interchangeability of loops
a statement 10 times
Nested loops
Printing patterns
Dynamic screen or dance on the screen
Generation of numbers
Prime, Armstrong, perfect, ninean,
eighteen...
Cup, mountain, palindrome
Slide numbers, climb up numbers
Oddeven sum equal
Alter sum equal
Triple sum equal
Generation of deadly sevens. Either divisible
by 7 or at least one digit is 7
Arrays
Declare
Initialize
Print all
Sum all
Modify all
Select on basis
Print function
Sort
Bubble
Selection
Insertion
Palarray
Print in reverse order
Reverse array and print
Find out the sum of digits in the array
Arrays and addresses
Pointer concept. Using a pointer, access another var,
change it, accept to it
Pointer arithmetic
Double pointer issues. Proper pictorial representations
Printing an array, given any address of the nth element
in array
Functions
Using built in functions with no arguments clrscr();
Using built in functions with arguments. Printf(“ ab”);
Using built in functions with varying arguments
printf(“%d %d “,a,b)
User defined functions, without arguments
User defined functions with arguments
User defined functions return vals
User defined functions with pass by reference
arguments
Two d arrays
Declaration and initialisation
Printing td arrays
Function to print/use td arrays
16 puzzle
Addresses in two D arrays
Sending any row’s address to a function
Diagonal elements
Major/ minor
Upper major/upper minor
Transpose
Addition
multiplication
Border elements
Inner elements
Steering rotation
Inner steering rotation
Check symmetric
Creation of magic square
Sum of rows/cols in a wrapper row/col
Check quadian matrix if every subsquare matrix
sum are equal
1 9 11 3
8 16 14 6
5 13 15 7
4 12 10 2
Reflections of td arrays
Rotations of td arrays
The cofactor of a matrix
Storage classes in C
Strings
Definition
Declaration
Initilisatioin
Searching
Sorting
Two arrays and strings
Malloc and pointer array of storing strings
Operations
Substring
Length
No. of vowels
No of words
Concatenation
Palindrome
Reversing a string
Change case of string
Upper/lower/toggle
Sorting of strings
Structure
Declaration
Initialisation
Copying
Printing values
Accepting values
By variable
By pointer
Array of structure
Array in a structure
Structure within a structure
Unions
Memory allocation
Pre-processor directives