Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
13 views

Lecture1 - Example

Uploaded by

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

Lecture1 - Example

Uploaded by

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

Programming Languages CSE

-271

Course Title: Introduction to Computer Programming

Presented By

Saadman Sakib

Lecturer,
Department of CSE,
CUET
Generations of Programming Language

The first generation languages, or 1GL: Low-level


languages that are machine language
The second generation languages, or 2GL: Also low-level
languages that generally consist of assembly languages
The third generation languages, or 3GL: High-level
languages
The fourth generation languages, or 4GL: Designed to build
specific programs, Commonly used in database programming and
scripts.
The fifth generation languages, or 5GL: Designed to make the
computer solve a given problem without the programmer.
Prolog is an example of fifth-generation languages.
Importance of C

 Robust language whose rich set of built-in functions


and operators can be used to write any complex
program
 Programs written in C are efficient and fast
 C is highly portable
 C language is well suited for structured programming
 Another important feature of C is its ability to extend
itself
Why C is Middle Level Language ?

• C Programming Supports Inline Assembly Language


Programs
• Using inline assembly language feature in C we
can directly access system registers
• C Programming is used to access memory directly using
pointer
• Combines features of high level language and functionality
of assembly language
• Well suited for writing both application software and system
software
Problem : Given two integers 20 and 10. Write a C program that uses a function add( ) to add
these two numbers and sub( ) to find the difference of these two numbers and then display the sum
and difference in the following form:
20 + 10 = 30
20 – 10 = 10

#include <stdio.h> int add(int a,int b)


int add(int a,int {
b); int sub(int return a+b;
}
a,int b); int
int sub(int a,int b)
main( ) {
{ return a-b;
int a=20,b=10; }
printf("%d + %d =
%d\
n",a,b,add(a,b));
printf("%d - %d = %d\n",a,b,sub(a,b));
return 0;
}
Problem: Area of a triangle

User-Defined
#include <stdio.h> Functions
#include
<math.h>
float area (float a,
float b,float c);
int main( )
{
float a,b,c;
printf("Enter size of each sides of triangle: ");
scanf("%f%f%f",&a,&b,&c);
printf("Area of the triangle is:
%f",area(a,b,c));
return 0;
}
float area (float a, float b,float c)
{
float s=(a+b+c)/2;
return sqrt(s*(s-a)*(s-b)*(s-c));
}
C program to calculate the distance between two points
#include <stdio.h>
#include <math.h>
float dist(float *x1, float *y1, float *x2, float *y2) Pointers
{
return sqrt((*x2 - *x1) * (*x2 - *x1) + (*y2 - *y1) * (*y2 -
*y1));
}
int main()
{
float result, a, b, c, d;
printf("\nEnter The Coordinates of Point A:\
n"); scanf("%f %f",&a,&b);
printf("\nEnter The Coordinates of Point B:\
n"); scanf("%f %f",&c,&d);
printf("\nDistance between Points A and B: %f\n",dist(&a, &b, &c,
&d)); return 0;
}
C Program to convert temperature from Celsius to Fahrenheit

#include <stdio.h>
int main()
{
float C,F;
printf("Enter temperature in Celsius:
"); scanf("%f",&C);
F= (C*9/5)+32;
printf("%.2f Celsius = %.2f Fahrenheit",C,F);
return 0;
}

You might also like