0% found this document useful (0 votes)
6 views16 pages

Lecture 1

Uploaded by

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

Lecture 1

Uploaded by

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

Computing Fundamentals

Introduction
C language
• Compact, fast, and powerful
• “Mid-level” Language
• Wide acceptance
• Supports modular programming style
• Useful for all
• Applications
• C is the native language of UNIX
Programming
• Computers are dumb devices that perform only the tasks applied by
the user
Levels of programming languages

Scripting language (R,


Python)
Mid/High level languages (C,
C++)

Assembly language

Machine language (Binary 0110010)

Hardware
C language
• (1970s) Pioneered by Dennis Ritchie
• Mid-level language
• (1983) Standardized by The American National Standards Institute
(ANSI)
• (1999) Last major changes adopted
First program
#include <stdio.h>
main()
{
/* My first program */
printf(“Alsalam Alikom \n");
}
• Case sensitive
• End each statement with a semicolon except comments
• Starting point identified by main()
• Braces {} signify the begin and end of the program
Understanding first program
• #include <stdio.h>
• Should be included at the beginning of every program
• Informs the compiler about the input and output statements like printf
• int main (void)
• Informs the compiler that the name of the program is main
• It returns an integer value “int.”
• main is a special name that indicates program execution starts.
• The keyword void that is enclosed in the parentheses specifies that the function
main takes no arguments
• return 0;
• Labels the completion of execution of main ,
• Returns to the system a status value of 0 (You can use any integer here)
• Zero is used by convention to indicate that the program completed successfully
Functions
• Will be discussed later on
Variable

Function

Return
printf options
• printf(“Alsalamo Alikom \n");
• function in the C library that simply prints or displays its argument on screen
• \n means newline. After printing Alsalam Alikom go to a new for extra printing
• All program statements in C must be terminated by a semicolon (;).

%i or %d int
%c char
%f float
%s string
How does the computer work
• What are the possible operations
• 2*2 What is pi?
• 4*A What is the
diameter?
What does the
• How to calculate the area of a circle?
area mean?
• Area=r*r*pi
Which numbers
are numeric and
which numbers
are float?
Declarations
• Declare an integer int x;
• Declare a charachter char x;
• Declare a float number (with decimal places)float x;
• Mulitple declarations are allowed  int x,y,z;

• Conditions of variable names


• Names are case sensitive ex. int x; int X;
• No dollar sign ex. int comp$fund;
• Underscores are allowed ex. int comp_fund;
• Names can contain numbers but not at the beginning ex int comp3; int 3comp;
• Names can not be keywords of C language ex. int int; int char; int long;
Initializations
• int x;
• x=5;
• int x=5;
• float pi=3.14;
• char x=‘A’;
• int x=5,y=3,z=2;
What is wrong here?
• int x
• int X$E;
• Int X=‘A’;
• Int X=3.14;
• Char X=3;
• char X=‘3’;
• Char ABC_DEF=‘A’
Arithmetic Operators in C language
Operator Description Example
+ Adds two operands. A + B = 30
Subtracts second operand from the
− A − B = -10
first.
A = 10 * Multiplies both operands. A * B = 200
B = 20
/ Divides numerator by de-numerator. B/A=2

Modulus Operator and remainder of


% B%A=0
after an integer division.
Increment operator increases the
++ A++ = 11
integer value by one.
Decrement operator decreases the
-- A-- = 9
integer value by one.

Decimal points will be lost if variable is declared as int instead of float


Area of a circle
#include<stdio.h>
main()
{
float radius, area;
radius=3.1;
area = 3.14 * radius * radius;
printf("Area of Circle : %f", area);
}
Lets test what we learned
#include <stdio.h>
6 + a / 5 * b = 16
int main (void) a / b * b = 24
{ c / d * d = 25.000000
-a = -25
int a = 25;
int b = 2;
float c = 25.0;
float d = 2.0;
printf ("6 + a / 5 * b = %i\n", 6 + a / 5 * b);
printf ("a / b * b = %i\n", a / b * b);
printf ("c / d * d = %f\n", c / d * d);
printf ("-a = %i\n", -a);
return 0;
}

You might also like