- Greater than < - Less than >= - Greater than or equal to <= - Less than or equal to These operators are used to compare two values and determine their relationship. They return a boolean true/false value which can be used to perform conditional operations."> - Greater than < - Less than >= - Greater than or equal to <= - Less than or equal to These operators are used to compare two values and determine their relationship. They return a boolean true/false value which can be used to perform conditional operations.">
MCS 011
MCS 011
Why C is referred as
middle level language ?
They are executed slower than lower level They execute with high speed.
languages because they require a translator
program.
They do not provide many facilities at the They are very close to the hardware and help
hardware level. to write a program at the hardware level.
For writing programs, hardware knowledge is not For writing programs, hardware knowledge is
required. a must.
A single statement may execute several The statements can be directly mapped to
instructions. processor instructions.
BASIC, Perl, Pascal, COBOL, Ruby etc are Machine language and Assembly language
examples of High-Level Languages. are Low-Level Languages.
void main()
{ <——————–Start of a Program
/*………….Printing Starts………….*/
/*………….Printing starts……..*/
} <———————-End of a Program
What is the purpose of using header files in C
For eg : Consider that you want to use printf("") function in C, so by including <stdio.h> header
file, you tell compiler that all the functions written in that header file should be accesibile in your
code and printf("") function is defined only in <stdio.h> file.
If you are more curious about whats in header file, go and open <stdio.h> file
in C:\TC\include folder and search for printf word, you will automatically understand.
Inshort, the working of all the functions are defined in various different header files. Like Math
functions are defined in “math.h” header file, String functions are defined in “string.h” header file
etc.
write a C program to divide two numbers
#include<stdio.h>
#include<conio.h>
void main(){
scanf("%d",&one);
scanf("%d",&two);
getch();
}
//End of the program.
add "n" numbers and find their average(2016
#include<stdio.h>
void main( )
{
int n, count = 1;
float x, average, sum = 0;
printf("Enter the value of n?");
scanf ("%d",&n);
while (count <= n)
{
printf ("Enter the %d number?",count);
scanf("%f", &x);
sum += x;
++count;
}
average = sum/n;
printf("\nThe Average is %f\n", average);
}
C program to find factorial of a number
#include <stdio.h>
long factorial(int);
int main()
{
int n;
printf("%d! = %ld\n", n, factorial(n));
return 0;
}
long factorial(int n)
{
int c;
long r = 1;
for (c = 1; c <= n; c++)
r = r * c;
return r;
}
convert a decimal number into an octal number equivalent
Solved Examples
Example 1: Convert (127)10 to Octal.
Solution: Divide 127 by 8
127 ÷ 8= 15(Quotient) and (7)Remainder
Divide 15 by 8 again.
15 ÷ 8 = 1(Quotient) and (7) Remainder
Divide 1 by 8, we get;
1 ÷ 8 = 0(Quotient) and (1) Remainder
Since the quotient is zero now, no more division can be done. So by taking the remainders in
reverse order, we get the equivalent octal number.
Hence, (127)10 = (177)8
RELATIONAL OPERATORS IN C:
Relational operators are used to find the relation between two variables. i.e. to compare the values of two
variables in a C program
main() {
int a = 21;
int b = 10;
int c ;
if( a == b ) {
printf("Line 1 - a is equal to b\n" );
} else {
printf("Line 1 - a is not equal to b\n" );
}
if ( a < b ) {
printf("Line 2 - a is less than b\n" );
} else {
printf("Line 2 - a is not less than b\n" );
}
if ( a > b ) {
printf("Line 3 - a is greater than b\n" );
} else {
printf("Line 3 - a is not greater than b\n" );
}
if ( a <= b ) {
printf("Line 4 - a is either less than or equal to b\n" );
}
if ( b >= a ) {
printf("Line 5 - b is either greater than or equal to b\n" );
}
}