Académique Documents
Professionnel Documents
Culture Documents
ConstantsVariables
Thevalueofaconstantcannotbechanged afteraninitialvalueisassignedtoit
Excercise01
SampleAnswer
1 /* Fig. 2.5: fig02_05.c 2 Addition program */ 3 #include <stdio.h> 4 5 int main() 6 { 7 int integer1, integer2, sum; 8 9 printf( "Enter first integer\n" ); 10 scanf( "%d", &integer1 ); 11 printf( "Enter second integer\n" ); 12 scanf( "%d", &integer2 ); 13 sum = integer1 + integer2; 14 printf( "Sum is %d\n", sum ); 15 16 return 0; /* indicate that program 17}
Enter first integer 45 Enter second integer 72 Sum is 117
/* declaration */ /* /* /* /* /* /* prompt */ read an integer */ prompt */ read an integer */ assignment of sum */ print sum */
ended successfully */
OperatorsinC
AssignmentOperator
Theassignmentoperatoristhesimpleequal sign(=)
a=5;//valueofvariableabecomes5 a=5+10;//valueofvariableabecomes15 a=5+b;//valueofvariableabecomes5+valueof b a=b+c;//valueofvariableabecomesvalueofb+ valueofc a=(x*x+y*y)/2;
compoundassignmentoperators
a=b;//issameasa=ab; a*=b;//issameasa=a*b; a/=b;//issameasa=a/b; a%=b;//issameasa=a%b;
Arithmeticoperations
Operator + * / % ++
ArithmeticoperationsinC
ArithmeticoperationsinC
ArithmeticoperationsExample
#include<stdio.h> intmain() { inta,b; printf("Entera:"); scanf("%d",&a);//readvalueofa printf("Enterb:"); scanf("%d",&b);//readvalueofb printf("\na+b=%d",a+b);//displaysumofa&b printf("\nab=%d",ab);//displaysubtractionofbfroma printf("\na*b=%d",a*b);//displaymultiplicationofa&b printf("\na/b=%d",a/b);//displaydivisionofabyb
printf("\na%%b=%d",a%b);//displaymodulusofadividedbyb
return0;}
Developingaprograminvolvesa setofsteps:
1.Definetheproblem 2.Outlinethesolution 3.Developanalgorithm1 4.Testthealgorithmforcorrectness 5.Codethealgorithmusingasuitable programminglanguage 6.Compileandcorrectionofcompileerrors 7.Runtheprogramonthecomputer
8.Test,documentandmaintaintheprogram
Excercise02
Assignment01
IncrementandDecrement Operators
incrementavariable: a=a+1; youmayuse: a+=1;ora++; Alsoexpression: a=a1; canbewrittenas: a=1;ora;
Exercise03
PrecedenceandAssociativelyof ArithmeticOperators
RelationalandLogicalOperators
PrecedenceofRelationaland LogicalOperators
PrecedenceofRelationaland LogicalOperators
Homework
BitwiseOperators ShiftOperators
Bestpractices
Testyourcodewhileyouareprogramming!
Questions??
Thankyou!