problem solving using c full course paart 1
problem solving using c full course paart 1
Introduction to C language:
Characteristics of C language,
Structure of a C Program.
Syntax and semantics
Data Types, Variables – declarations and initialization,
formatting input and output.
Get Print
calculate
configuration report
desktop Laptop
DELL HP DELL HP
Pseudo Code:
1. If student's grade is greater than or equal
to 60
1.1 Print "passed"
2. else
2.1 Print "failed"
Algorithm:
Begin
1. If grade >= 60
1.1 Print "passed"
2. else
2.1 Print "failed”
End
Start
input a, b
c=a+b
Display C
End
Algorithm:
BEGIN
Step 1: Accept the YEAR
Step 2: if (YEAR %4 == 0) then
Display “Year is a leap year”
else
Display “Year is not a leap year”
end if
END
Start
Accept year
false
if(year%4 = = 0)
true
Display non leap year
Display leap year
End
K.Vigneswara Reddy, Dept. of I.T, SNIST
Introduction to Computer
Programming Languages
continued
Semantics:
For example:
character constant „a‟ has an int value 97, „b‟ - 98, „A‟ - 65 etc.
The keyword char is used to declare a variable of a character type.
If you know that the variable cannot have negative values, you may declare it
as unsigned.
unsigned variable type occupies the same amount of computer memory as int
but the actual value can be twice as large as the maximum available int,
because all values are positive.
To decrease the size of allocated memory for a variable which is not too large,
you may use the short type which is stored in 2 bytes
-> The data type float represents a floating point number (also called a real
number or numbers with decimal ).
->The keyword float is used to declare a variable of the type float.
Ex: float float_num1=1.34;
-> The float type variable is usually stored in 4 bytes, which means it is at least
6 digits of precision.
K.Vigneswara Reddy, Dept. of I.T, SNIST
The double Data Type
A floating point number can also be represented by the double data type.
The data type double is stored on most machines in 8 bytes which is about 15
decimal places of accuracy.
To declare a variable of the type double, use the keyword double.
char 1 -128
-127 or 0 127 or 255
127 ’a’, 123, ’\n’ %c
Program
#include<stdio.h>
main()
{ Note – variables must be
int a=10,b=20,c; declared before they are
c=a+b; used, usually at the
printf(“sum of a and b=%d\n”,c);
return 0;
beginning of the function.
}
o/p- sum of a and b=30
Definition- variable which stores the value in the memory location, that value varies
during program execution
variables in the above program are a b and c .
Percent Legal
y2x5__fg7h Legal
annual_profit Legal
_1990_tax Legal but not advised
savings#account Illegal: Contains the illegal character #
double Illegal: Is a C keyword
9winter Illegal: First character is a digit
int a;
Variable declaration and definition
Variable name
a
23456 Garbage value
Mantissa e exponent
double 0. 0.0
double 0.0 .0
Defined constants:
By using the preprocessor command you can create a
constant.
Example: #define pi 3.14
Memory constants:
Memory constants use a C type qualifier, const, to indicate
that the data can not be changed.
Its format is: const type identifier = value;
Example: const float PI = 3.14159;
Conversion Specification
K.Vigneswara Reddy, Dept. of I.T, SNIST
Flag Formatting Options
K.Vigneswara Reddy, Dept. of I.T, SNIST
Format Codes for Output
K.Vigneswara Reddy, Dept. of I.T, SNIST
K.Vigneswara Reddy, Dept. of I.T, SNIST
K.Vigneswara Reddy, Dept. of I.T, SNIST
K.Vigneswara Reddy, Dept. of I.T, SNIST
K.Vigneswara Reddy, Dept. of I.T, SNIST
K.Vigneswara Reddy, Dept. of I.T, SNIST
scanf(“control string”,&var1,&var2.. &varn);
control string includes format specifiers and specifies the field width.