ME 172 Introduction To Programming Language: Class 3
ME 172 Introduction To Programming Language: Class 3
Introduction to C Programming
Language
Class 3
Cyrus Ashok Arupratan Atis
Lecturer,Dept. of ME,BUET
M Aminul Hoque
Lecturer,Dept. of ME,BUET
10/3/2015
Performance Test
Example
#include <stdio.h>
#include <conio.h>
void main(void)
{
char test;
printf(Type any character: );
test = getch();
printf(\nThe character you typed was:
%c,test);
}
Replace getch() with getche()
Arithmetic operators
Operator
Name
Example
Addition
a+b
Subtraction
ab
Multiplication
a*b
Division
a/b
Remainder
a%b
++
Increment
++a/a++
--
Decrement
--a/a--
Arithmetic operator(Contd...)
++a/a++ is equivalent to a=a+1
--a/a-- is equivalent to a=a-1
++m and m++
Prefix operator
Postfix operator
Arithmetic operator(Contd...)
x=x*a++
Arithmetic Operators(Contd...)
Write the following program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a=10,b=20,x;
x=a*++b;
printf("\n The value of x is:
%d,x);
getch();
}
Replace the line x=a*++b with x=a*b++
Arithmetic Operator(Contd...)
Shorthand Notation
Operator
+=
Description
Add AND assignment operator
Example
C += A is equivalent to
C= C +A
-=
C -= A is equivalent to
C= C -A
*=
/=
C /= A is equivalent to
C= C /A
Practice Example
#include<stdio.h>
void main ()
{
int x=10;
x+=3;
printf(%d,x);
}
Description
exp
sqrt
cos
pow
sinh
erf
error function
And so on.
Description
M_E
M_LOG2E
M_PI
3.141593
M_SQRT2
M_SQRT1_2
And so on.
Practice Problem
Write a program that takes two numbers as input.
Find the square root of the first number and the resulting
output will be the radius of a cylinder.
Raise the second input number to a power of 5. The
resulting output will be the height of the cylinder.
Find the volume of the cylinder by using the saved value of
pi in the header file.
Remember to use the math.h file.
10/3/2015
13
14
Thank you
Everything has its beginning. But it doesn't start at "one."
-Big Boss (Metal Gear Solid 4)
10/3/2015
18