SlideShare une entreprise Scribd logo
1  sur  12
Télécharger pour lire hors ligne
Introduction to Computers and
Programming (CSC103)
Lecture 04
2
void main (void)
{
printf("Testing...n..1n...2n....3n")
}
Compilation Result?
#include <stdio.h>
void main (void)
{
value1 = 50;
value2 = 25;
int value1, value2, sum;
sum = value1 + value2;
printf("The sum of %d and %d is %dn", value1, value2, sum);
}
Compilation Result?
1
2
3
#include <stdio.h>
void main (void)
{
printf ("Testing...n..1n...2n....3n");
}
Output?
#include <stdio.h>
void main (void)
{
int value1, value2, sum;
value1 = 50;
value2 = 25;
sum = value1 + value2;
printf("The sum of %d and %d is %dn", value1, value2, sum);
}
Output?
1
2
Arithmetic Instructions in C
4
int ad ;
float kot, deta, alpha, beta, gamma;
ad = 3200 ;
kot = 0.0056 ;
deta = alpha * beta / gamma + 3.2 * 2 / 5 ;
---------------------------------------------------------------------------------
Here,
*, /, -, + are the arithmetic operators.
= is the assignment operator.
2, 5 and 3200 are integer constants.
3.2 and 0.0056 are real constants.
ad is an integer variable.
kot, deta, alpha, beta, gamma are real variables.
Variable Declaration and Use
5
Correct Incorrect
float a = 1.5, b = a + 3.1; float b = a + 3.1, a = 1.5;
int a, b, c, d ;
a = b = c = 10 ;
int a = b = c = d = 10;
int x, y, z;
x = y * z;
int x, y, z;
y * z = x;
Cannot Use aVariable before declaring it!
Integer and Float Conversion
6
 Implicit and Explicit Conversions
 An arithmetic operation between an integer and integer
always yields an integer result.
 An operation between a real and real always yields a real
result.
 An operation between an integer and real always yields a real
result. In this operation the integer is first promoted to a real
and then the operation is performed. Hence the result is real.
7
int i ;
float b ;
i = 3.5 ;
b = 30 ;
 What would be the value of i and b?
 Think of Integer and Float Conversion
8
 k is an integer variable
 a is a real/float variable
Receiving User Input
 To get the input from the user we use a library function called
scanf()
 The format of scanf() is;
scanf(“<format specifier>”, &<variable name>);
 format specifier shows what type of data you want to input or get
from user
 & before the variable name is must
 & is an “Address of Operator”
 It gives the location number used by the variable in memory
 &num tells the scanf() function at which memory location should
it store the value supplied by the user
 a blank, a tab or a new line (pressing enter) must separate the values
supplied to scanf()
Example: scanf(“%d %d %f”, &p,&n,&r);
9
Example
#include<stdio.h>
void main()
{
int num;
printf(“Enter an Integer: ”);
scanf(“%d”, &num);
printf(“You entered the number %d”, num);
}
Output?
10
Example # 2
11
#include<stdio.h>
void main()
{
int x, y;
scanf("%d%d",&x,&y);
printf(“You have entered x=%d, y=%d",x,y);
}
Output?
Evaluate yourself!
12
 Point out the errors, if any, in the following C statements:
(a) int = 314.562 * 150 ;
(b) name = ‘Ajay’ ;
(c) varchar = ‘3’ ;
(d) 3.14 * r * r * h = vol_of_cyl ;
(e) k = ( a * b ) ( c + ( 2.5a + b ) ( d + e ) ;
(f) m_inst = rate of interest * amount in rs ;

Contenu connexe

Tendances

C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2Zaibi Gondal
 
C Programming Language Part 4
C Programming Language Part 4C Programming Language Part 4
C Programming Language Part 4Rumman Ansari
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8Rumman Ansari
 
print even or odd number in c
print even or odd number in cprint even or odd number in c
print even or odd number in cmohdshanu
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c languageMomenMostafa
 
C programming pointer
C  programming pointerC  programming pointer
C programming pointerargusacademy
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentalsZaibi Gondal
 
function in c
function in cfunction in c
function in csubam3
 
please sir i want to comments of every code what i do in eachline . in this w...
please sir i want to comments of every code what i do in eachline . in this w...please sir i want to comments of every code what i do in eachline . in this w...
please sir i want to comments of every code what i do in eachline . in this w...hwbloom27
 
Simple c program
Simple c programSimple c program
Simple c programRavi Singh
 
C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloadingmohamed sikander
 
Mathematics Function in C ,ppt
Mathematics Function in C ,pptMathematics Function in C ,ppt
Mathematics Function in C ,pptAllNewTeach
 
How c program execute in c program
How c program execute in c program How c program execute in c program
How c program execute in c program Rumman Ansari
 

Tendances (20)

C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2
 
C Programming Language Part 4
C Programming Language Part 4C Programming Language Part 4
C Programming Language Part 4
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
print even or odd number in c
print even or odd number in cprint even or odd number in c
print even or odd number in c
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c language
 
C programming pointer
C  programming pointerC  programming pointer
C programming pointer
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
function in c
function in cfunction in c
function in c
 
lets play with "c"..!!! :):)
lets play with "c"..!!! :):)lets play with "c"..!!! :):)
lets play with "c"..!!! :):)
 
please sir i want to comments of every code what i do in eachline . in this w...
please sir i want to comments of every code what i do in eachline . in this w...please sir i want to comments of every code what i do in eachline . in this w...
please sir i want to comments of every code what i do in eachline . in this w...
 
Simple c program
Simple c programSimple c program
Simple c program
 
Functions
FunctionsFunctions
Functions
 
C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloading
 
Mathematics Function in C ,ppt
Mathematics Function in C ,pptMathematics Function in C ,ppt
Mathematics Function in C ,ppt
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
Class 6 2ciclo
Class 6 2cicloClass 6 2ciclo
Class 6 2ciclo
 
Function & Recursion in C
Function & Recursion in CFunction & Recursion in C
Function & Recursion in C
 
How c program execute in c program
How c program execute in c program How c program execute in c program
How c program execute in c program
 
6. function
6. function6. function
6. function
 

En vedette

Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03hassaanciit
 
Introduction to Computer and Programing - Lab2
Introduction to Computer and Programing - Lab2Introduction to Computer and Programing - Lab2
Introduction to Computer and Programing - Lab2hassaanciit
 
Introduction to Computer and Programming - Lecture 02
Introduction to Computer and Programming - Lecture 02Introduction to Computer and Programming - Lecture 02
Introduction to Computer and Programming - Lecture 02hassaanciit
 
Introduction to Computer and Programming - Lecture 01
Introduction to Computer and Programming - Lecture 01Introduction to Computer and Programming - Lecture 01
Introduction to Computer and Programming - Lecture 01hassaanciit
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming conceptssalmankhan570
 
Computer programing
Computer programingComputer programing
Computer programingJT Taylor
 
DBIx::Class introduction - 2010
DBIx::Class introduction - 2010DBIx::Class introduction - 2010
DBIx::Class introduction - 2010leo lapworth
 
Object-Oriented Programming 2
Object-Oriented Programming 2Object-Oriented Programming 2
Object-Oriented Programming 2Warawut
 
System software lecture infs429
System software lecture infs429System software lecture infs429
System software lecture infs429Edmund Sowah
 
Islamic Studies - Lecture#1 (Religion)
Islamic Studies - Lecture#1 (Religion)Islamic Studies - Lecture#1 (Religion)
Islamic Studies - Lecture#1 (Religion)hassaanciit
 
Introduction to basic programming
Introduction to basic programmingIntroduction to basic programming
Introduction to basic programmingJordan Delacruz
 
The Basics of programming
The Basics of programmingThe Basics of programming
The Basics of programming692sfrobotics
 
PowerPoint for Introduction to Office 2010
PowerPoint for Introduction to Office 2010PowerPoint for Introduction to Office 2010
PowerPoint for Introduction to Office 2010mindysholder
 

En vedette (20)

Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03
 
Introduction to Computer and Programing - Lab2
Introduction to Computer and Programing - Lab2Introduction to Computer and Programing - Lab2
Introduction to Computer and Programing - Lab2
 
Introduction to Computer and Programming - Lecture 02
Introduction to Computer and Programming - Lecture 02Introduction to Computer and Programming - Lecture 02
Introduction to Computer and Programming - Lecture 02
 
Introduction to Computer and Programming - Lecture 01
Introduction to Computer and Programming - Lecture 01Introduction to Computer and Programming - Lecture 01
Introduction to Computer and Programming - Lecture 01
 
Programing Fundamental
Programing FundamentalPrograming Fundamental
Programing Fundamental
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
 
Basic programming
Basic programmingBasic programming
Basic programming
 
Computer Programing
Computer ProgramingComputer Programing
Computer Programing
 
Computer programing
Computer programingComputer programing
Computer programing
 
DBIx::Class introduction - 2010
DBIx::Class introduction - 2010DBIx::Class introduction - 2010
DBIx::Class introduction - 2010
 
Programing techniques
Programing techniquesPrograming techniques
Programing techniques
 
Object-Oriented Programming 2
Object-Oriented Programming 2Object-Oriented Programming 2
Object-Oriented Programming 2
 
System software lecture infs429
System software lecture infs429System software lecture infs429
System software lecture infs429
 
Sharia
ShariaSharia
Sharia
 
Islamic Studies - Lecture#1 (Religion)
Islamic Studies - Lecture#1 (Religion)Islamic Studies - Lecture#1 (Religion)
Islamic Studies - Lecture#1 (Religion)
 
Introduction to basic programming
Introduction to basic programmingIntroduction to basic programming
Introduction to basic programming
 
The Basics of programming
The Basics of programmingThe Basics of programming
The Basics of programming
 
What is Sharia Law?
What is Sharia Law?What is Sharia Law?
What is Sharia Law?
 
PowerPoint for Introduction to Office 2010
PowerPoint for Introduction to Office 2010PowerPoint for Introduction to Office 2010
PowerPoint for Introduction to Office 2010
 
Islam s6 shari'a law and dhimmi
Islam s6 shari'a law and dhimmiIslam s6 shari'a law and dhimmi
Islam s6 shari'a law and dhimmi
 

Similaire à Introduction to Computer and Programing - Lecture 04

Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 FocJAYA
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]Abhishek Sinha
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxhappycocoman
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02Wingston
 
Chap 2 input output dti2143
Chap 2  input output dti2143Chap 2  input output dti2143
Chap 2 input output dti2143alish sha
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4MKalpanaDevi
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of cTushar B Kute
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statementsMomenMostafa
 

Similaire à Introduction to Computer and Programing - Lecture 04 (20)

Function in c program
Function in c programFunction in c program
Function in c program
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
C programs
C programsC programs
C programs
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
7 functions
7  functions7  functions
7 functions
 
Functions in c
Functions in cFunctions in c
Functions in c
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
 
Chap 2 input output dti2143
Chap 2  input output dti2143Chap 2  input output dti2143
Chap 2 input output dti2143
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
Functions
FunctionsFunctions
Functions
 
C function
C functionC function
C function
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Muzzammilrashid
MuzzammilrashidMuzzammilrashid
Muzzammilrashid
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 

Plus de hassaanciit

Circuits Lecture 5 with examples
Circuits Lecture 5 with examplesCircuits Lecture 5 with examples
Circuits Lecture 5 with exampleshassaanciit
 
Calculus - Functions Review
Calculus - Functions ReviewCalculus - Functions Review
Calculus - Functions Reviewhassaanciit
 
Ex 1 3_fsc_part1
Ex 1 3_fsc_part1Ex 1 3_fsc_part1
Ex 1 3_fsc_part1hassaanciit
 
Islamic Studies - Fundamental beliefs
Islamic Studies - Fundamental beliefsIslamic Studies - Fundamental beliefs
Islamic Studies - Fundamental beliefshassaanciit
 
Islamic Studies - Concepts About Religion
Islamic Studies - Concepts About ReligionIslamic Studies - Concepts About Religion
Islamic Studies - Concepts About Religionhassaanciit
 
Islamic Studies - Course Outline
Islamic Studies - Course OutlineIslamic Studies - Course Outline
Islamic Studies - Course Outlinehassaanciit
 

Plus de hassaanciit (7)

Circuits Lecture 5 with examples
Circuits Lecture 5 with examplesCircuits Lecture 5 with examples
Circuits Lecture 5 with examples
 
ICP - Lecture 9
ICP - Lecture 9ICP - Lecture 9
ICP - Lecture 9
 
Calculus - Functions Review
Calculus - Functions ReviewCalculus - Functions Review
Calculus - Functions Review
 
Ex 1 3_fsc_part1
Ex 1 3_fsc_part1Ex 1 3_fsc_part1
Ex 1 3_fsc_part1
 
Islamic Studies - Fundamental beliefs
Islamic Studies - Fundamental beliefsIslamic Studies - Fundamental beliefs
Islamic Studies - Fundamental beliefs
 
Islamic Studies - Concepts About Religion
Islamic Studies - Concepts About ReligionIslamic Studies - Concepts About Religion
Islamic Studies - Concepts About Religion
 
Islamic Studies - Course Outline
Islamic Studies - Course OutlineIslamic Studies - Course Outline
Islamic Studies - Course Outline
 

Dernier

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Dernier (20)

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

Introduction to Computer and Programing - Lecture 04

  • 1. Introduction to Computers and Programming (CSC103) Lecture 04
  • 2. 2 void main (void) { printf("Testing...n..1n...2n....3n") } Compilation Result? #include <stdio.h> void main (void) { value1 = 50; value2 = 25; int value1, value2, sum; sum = value1 + value2; printf("The sum of %d and %d is %dn", value1, value2, sum); } Compilation Result? 1 2
  • 3. 3 #include <stdio.h> void main (void) { printf ("Testing...n..1n...2n....3n"); } Output? #include <stdio.h> void main (void) { int value1, value2, sum; value1 = 50; value2 = 25; sum = value1 + value2; printf("The sum of %d and %d is %dn", value1, value2, sum); } Output? 1 2
  • 4. Arithmetic Instructions in C 4 int ad ; float kot, deta, alpha, beta, gamma; ad = 3200 ; kot = 0.0056 ; deta = alpha * beta / gamma + 3.2 * 2 / 5 ; --------------------------------------------------------------------------------- Here, *, /, -, + are the arithmetic operators. = is the assignment operator. 2, 5 and 3200 are integer constants. 3.2 and 0.0056 are real constants. ad is an integer variable. kot, deta, alpha, beta, gamma are real variables.
  • 5. Variable Declaration and Use 5 Correct Incorrect float a = 1.5, b = a + 3.1; float b = a + 3.1, a = 1.5; int a, b, c, d ; a = b = c = 10 ; int a = b = c = d = 10; int x, y, z; x = y * z; int x, y, z; y * z = x; Cannot Use aVariable before declaring it!
  • 6. Integer and Float Conversion 6  Implicit and Explicit Conversions  An arithmetic operation between an integer and integer always yields an integer result.  An operation between a real and real always yields a real result.  An operation between an integer and real always yields a real result. In this operation the integer is first promoted to a real and then the operation is performed. Hence the result is real.
  • 7. 7 int i ; float b ; i = 3.5 ; b = 30 ;  What would be the value of i and b?  Think of Integer and Float Conversion
  • 8. 8  k is an integer variable  a is a real/float variable
  • 9. Receiving User Input  To get the input from the user we use a library function called scanf()  The format of scanf() is; scanf(“<format specifier>”, &<variable name>);  format specifier shows what type of data you want to input or get from user  & before the variable name is must  & is an “Address of Operator”  It gives the location number used by the variable in memory  &num tells the scanf() function at which memory location should it store the value supplied by the user  a blank, a tab or a new line (pressing enter) must separate the values supplied to scanf() Example: scanf(“%d %d %f”, &p,&n,&r); 9
  • 10. Example #include<stdio.h> void main() { int num; printf(“Enter an Integer: ”); scanf(“%d”, &num); printf(“You entered the number %d”, num); } Output? 10
  • 11. Example # 2 11 #include<stdio.h> void main() { int x, y; scanf("%d%d",&x,&y); printf(“You have entered x=%d, y=%d",x,y); } Output?
  • 12. Evaluate yourself! 12  Point out the errors, if any, in the following C statements: (a) int = 314.562 * 150 ; (b) name = ‘Ajay’ ; (c) varchar = ‘3’ ; (d) 3.14 * r * r * h = vol_of_cyl ; (e) k = ( a * b ) ( c + ( 2.5a + b ) ( d + e ) ; (f) m_inst = rate of interest * amount in rs ;