- 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.">
[go: up one dir, main page]

0% found this document useful (0 votes)
55 views8 pages

MCS 011

Here are the key relational operators in C: == - Equal to != - Not equal to > - 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.

Uploaded by

JithuHashMi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views8 pages

MCS 011

Here are the key relational operators in C: == - Equal to != - Not equal to > - 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.

Uploaded by

JithuHashMi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

What is the difference between High level language and low level language ?

Why C is referred as
middle level language ?

High-Level Languages Low-Level Languages


High-Level Languages are easy to learn and Low-Level Languages are challenging to
understand. learn and understand.

They are executed slower than lower level They execute with high speed.
languages because they require a translator
program.

They allow much more abstraction. They allow little or no abstraction.

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.

The programs are easy to modify. Modifying programs is difficult.

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.

Why is C called Middle-level language?


C is usually called a middle-level language as it stands between high-level languages
and low-level languages. This is because C language instructions resemble the normal
algebraic expressions along with certain English keyword like if, else, for etc. In this
respect, C resembles a high-level language. But it also posses certain low-level features
that help the programmers to carry out operations available in assembly or machine
languages. For example, it permits the manipulation of individual bits and also values of
certain variables can be sorted within the CPU's registers to speed up the computation
associated with these values.
Thus, C can be used for systems programming (eg., for writing operating systems) as
well as applications programming (e.g. to solve a complicated system of mathematical
equations, or for writing a program to bill customers).
Basic Structure of a C Program:

 Documentation section : The documentation section consists of a set of comment


lines giving the name of the program, the author and other details, which the
programmer would like to use later.
 Link section : The link section provides instructions to the compiler to link functions
from the system library.
 Definition section : The definition section defines all symbolic constants.
 Global declaration section : There are some variables that are used in more than
one function. Such variables are called global variables and are declared in the global
declaration section that is outside of all the functions. This section also declares all the
user-defined functions.
 main () function section : Every C program must have one main function section.
This section contains two parts; declaration part and executable partDeclaration
part : The declaration part declares all the variables used in the executable
part.Executable part : There is at least one statement in the executable part. These
two parts must appear between the opening and closing braces. The program
execution begins at the opening brace and ends at the closing brace. The closing
brace of the main function is the logical end of the program. All statements in the
declaration and executable part end with a semicolon.
 Subprogram section : The subprogram section contains all the user-defined
functions that are called in the main () function. User-defined functions are generally
placed immediately after the main () function, although they may appear in any order.
Note:All section, except the main () function section may be absent when they are not
required.
Sample C Program:

#include<stdio.h> <———————-Preprocessing Directive

void main()

{ <——————–Start of a Program

/*………….Printing Starts………….*/

Printf(“Learn at every moment”);

/*………….Printing starts……..*/

} <———————-End of a Program
What is the purpose of using header files in C

These are preprocessor directives.


The reason we include them is to make compiler aware of what functions we need to use.

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.

There will be many other functions defined in it !

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

/*Program to divide two numbers in C.


Programmer: Harsh Shah, Date: 29/6/13*/

#include<stdio.h>
#include<conio.h>

void main(){

int one, two, div;

printf("Enter first number - ");

scanf("%d",&one);

printf("Enter second number - ");

scanf("%d",&two);

div = one / two;

printf("The divison of numbers %d and %d is %d",one,two,div);

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("Enter a number to calculate its factorial\n");


  scanf("%d", &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" );
}

/* Lets change value of a and b */


a = 5;
b = 20;

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" );
}
}

You might also like