SlideShare uma empresa Scribd logo
1 de 7
HaNoi University of Technology Week 2:Core C# Programming Constructs – Mastering C# 2008
Week 2: Core C# Programming Constructs
Topics
• Constants & Variable
• Statements and Expressions
• Control Flow
PART I: C # BASIC
Exercise 1
Which letters represent valid identifiers?
a) Abc e) $$$ i) a_1
b) M/H f) 25or6to4 j) Student Number
c) Main g) 1_time k) string
d) double h) first-Name
Valid identifiers are ______________________________________________
Invalid identifiers are ____________________________________________
Exercise 2
using System;
class Class1
{
static void Main()
{
const int y = 1,z = 2;
const string x = "Hello";
string X = "World";
Console.WriteLine(y + z);
Console.WriteLine(x + " " + X);
Console.ReadLine();
}
}
2.1 What is written by this program?
1/6
HaNoi University of Technology Week 2:Core C# Programming Constructs – Mastering C# 2008
2.2 List all variables in this program.
Exercise 3
using System;
class Class1
{
static void Main()
{
const int b=a+1; //1
const int d=c+3; //2
const int c=b+2; //3
const int a=1; //4
Console.WriteLine(a + b + c + d);
Console.ReadLine();
}
}
3.1 From this program, when compiled, there are some errors. Why?
3.2 This program can be corrected by rearrangement of lines (1) to (4).
Rewrite CONSTANT DECLARATION PART of this program to correct it.
________________________
________________________
________________________
________________________
2/6
HaNoi University of Technology Week 2:Core C# Programming Constructs – Mastering C# 2008
Exercise 4
static void Main()
{
string s = "abc"; //1
int n = 0; //2
double x = 0.0; //3
s = n; //4
n = 1.0; //5
n = x; //6
x = 999; //7
x += n; //8
s = "abc" + 1; //9
s -= 1; //10
n = 1 + 1.5; //11
}
In which line of this program (4-11) did errors occur?
Line The problem is …
3/6
HaNoi University of Technology Week 2:Core C# Programming Constructs – Mastering C# 2008
PART II: Operators and Priorities
Precedence Order Operator
1 ()
2 ++(x),--(x),+(x),-(x)
3 *,/,%
4 +,-
5 =,+=,-=,*=,/=,%=
6 (x)++,(x)--
Exercise 5
class Test
{
static void Main()
{
double x = 3.0, y = 2.0;
int a = 10, b = 2;
(1)
Console.ReadLine();
}
}
Insert the line numbered (1) using instructions from the following table.
Fill the column output.
(1) Output
Console.WriteLine(x+a);
Console.WriteLine(a/b);
Console.WriteLine(y/x);
Console.WriteLine(y%x);
Console.WriteLine(++y%x-1);
Console.WriteLine(y--%x+1);
Console.WriteLine(a+b%b);
Console.WriteLine(x/y*b);
Console.WriteLine((a+b)/b%a);
Console.WriteLine(9.0/5.0*(a-x));
Console.WriteLine(x+y-x*y%x);
Console.WriteLine(57%50/25);
4/6
HaNoi University of Technology Week 2:Core C# Programming Constructs – Mastering C# 2008
PART III: Control Flow
Exercise 6
class IfElseStruct
{
static void Main()
{
int x = 15;
int y=20 ;
if(x>y)Console.WriteLine(x);
else Console.WriteLine(y) ;
Console.ReadLine();
}
}
What is written from this program?
Exercise 7
class ForStruct
{
static void Main()
{
for(int i=1 ;i<10 ;i++){
Console.WriteLine(i*i);
}
Console.ReadLine();
}
}
What is written from this program?
Exercise 8
using System;
{
class WhileStruct
5/6
HaNoi University of Technology Week 2:Core C# Programming Constructs – Mastering C# 2008
{
static void Main()
{
int n=10;
while(true){
if(n>0){
Console.WriteLine(n);
n--;
}
else break;
}
Console.ReadLine();
}
}
}
What is written from this program?
Exercise 9
using System;
{
class Foreach
{
static void Main()
{
int[] A={10,9,8,7,6,5,4,3,2,1};
foreach(var x in A){
Console.WriteLine(x);
}
Console.ReadLine();
}
}
}
What is written from this program?
6/6
HaNoi University of Technology Week 2:Core C# Programming Constructs – Mastering C# 2008
{
static void Main()
{
int n=10;
while(true){
if(n>0){
Console.WriteLine(n);
n--;
}
else break;
}
Console.ReadLine();
}
}
}
What is written from this program?
Exercise 9
using System;
{
class Foreach
{
static void Main()
{
int[] A={10,9,8,7,6,5,4,3,2,1};
foreach(var x in A){
Console.WriteLine(x);
}
Console.ReadLine();
}
}
}
What is written from this program?
6/6

Mais conteúdo relacionado

Mais procurados

FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMINGFINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
Amira Dolce Farhana
 

Mais procurados (20)

Mca 104
Mca 104Mca 104
Mca 104
 
CP Handout#3
CP Handout#3CP Handout#3
CP Handout#3
 
Ocs752 unit 2
Ocs752   unit 2Ocs752   unit 2
Ocs752 unit 2
 
Visual Basic Source Codes for Class 11 HSc Paper 1 Practicals
Visual Basic Source Codes for Class 11 HSc Paper 1 PracticalsVisual Basic Source Codes for Class 11 HSc Paper 1 Practicals
Visual Basic Source Codes for Class 11 HSc Paper 1 Practicals
 
Ocs752 unit 3
Ocs752   unit 3Ocs752   unit 3
Ocs752 unit 3
 
Sample quizz test
Sample quizz testSample quizz test
Sample quizz test
 
CP Handout#5
CP Handout#5CP Handout#5
CP Handout#5
 
2. introduction of a c program
2. introduction of a c program2. introduction of a c program
2. introduction of a c program
 
Handout#08
Handout#08Handout#08
Handout#08
 
Course File c++
Course File c++Course File c++
Course File c++
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
 
Ocs752 unit 1
Ocs752   unit 1Ocs752   unit 1
Ocs752 unit 1
 
CP Handout#7
CP Handout#7CP Handout#7
CP Handout#7
 
Oop december 2018
Oop december 2018Oop december 2018
Oop december 2018
 
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMINGFINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
 
CP Handout#6
CP Handout#6CP Handout#6
CP Handout#6
 
Keywords in c language
Keywords in c languageKeywords in c language
Keywords in c language
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
FP 301 OOP FINAL PAPER
FP 301 OOP FINAL PAPER FP 301 OOP FINAL PAPER
FP 301 OOP FINAL PAPER
 
175035 cse lab 01
175035 cse lab 01175035 cse lab 01
175035 cse lab 01
 

Destaque

Kaizo advcoacy index 2011 slide show
Kaizo advcoacy index 2011 slide showKaizo advcoacy index 2011 slide show
Kaizo advcoacy index 2011 slide show
thomasreast
 
Athena huong danhoc quantri mangcoban_acbn
Athena huong danhoc quantri mangcoban_acbnAthena huong danhoc quantri mangcoban_acbn
Athena huong danhoc quantri mangcoban_acbn
Chi Lam
 
"The New Woman"
"The New Woman""The New Woman"
"The New Woman"
suzgaray
 
"The Road Less Traveled"
"The Road Less Traveled""The Road Less Traveled"
"The Road Less Traveled"
suzgaray
 

Destaque (18)

Appin Franchise India Final
Appin  Franchise India FinalAppin  Franchise India Final
Appin Franchise India Final
 
Biffle
BiffleBiffle
Biffle
 
Kaizo advcoacy index 2011 slide show
Kaizo advcoacy index 2011 slide showKaizo advcoacy index 2011 slide show
Kaizo advcoacy index 2011 slide show
 
Propuesta ingles
Propuesta inglesPropuesta ingles
Propuesta ingles
 
ΘΑΛΗΣ 2014 ΕΚΦΩΝΗΣΕΙΣ-ΛΥΣΕΙΣ
ΘΑΛΗΣ 2014 ΕΚΦΩΝΗΣΕΙΣ-ΛΥΣΕΙΣΘΑΛΗΣ 2014 ΕΚΦΩΝΗΣΕΙΣ-ΛΥΣΕΙΣ
ΘΑΛΗΣ 2014 ΕΚΦΩΝΗΣΕΙΣ-ΛΥΣΕΙΣ
 
Biffle - Instructional Leadership
Biffle - Instructional LeadershipBiffle - Instructional Leadership
Biffle - Instructional Leadership
 
Biffle - Instructional Leadership
Biffle - Instructional LeadershipBiffle - Instructional Leadership
Biffle - Instructional Leadership
 
Biffle
BiffleBiffle
Biffle
 
ΘΑΛΗΣ 2015 ΕΚΦΩΝΗΣΕΙΣ-ΛΥΣΕΙΣ
ΘΑΛΗΣ 2015 ΕΚΦΩΝΗΣΕΙΣ-ΛΥΣΕΙΣΘΑΛΗΣ 2015 ΕΚΦΩΝΗΣΕΙΣ-ΛΥΣΕΙΣ
ΘΑΛΗΣ 2015 ΕΚΦΩΝΗΣΕΙΣ-ΛΥΣΕΙΣ
 
Athena huong danhoc quantri mangcoban_acbn
Athena huong danhoc quantri mangcoban_acbnAthena huong danhoc quantri mangcoban_acbn
Athena huong danhoc quantri mangcoban_acbn
 
"The New Woman"
"The New Woman""The New Woman"
"The New Woman"
 
File goc 782889
File goc 782889File goc 782889
File goc 782889
 
"The Road Less Traveled"
"The Road Less Traveled""The Road Less Traveled"
"The Road Less Traveled"
 
Α Γυμνασίου Κεφάλαιο 7 - επανάληψη
Α Γυμνασίου Κεφάλαιο 7 - επανάληψηΑ Γυμνασίου Κεφάλαιο 7 - επανάληψη
Α Γυμνασίου Κεφάλαιο 7 - επανάληψη
 
Tauranga
TaurangaTauranga
Tauranga
 
College loans no cosigner
College loans no cosignerCollege loans no cosigner
College loans no cosigner
 
Leadership project final
Leadership project finalLeadership project final
Leadership project final
 
ΘΑΛΗΣ 2012 ΕΚΦΩΝΗΣΕΙΣ
ΘΑΛΗΣ 2012 ΕΚΦΩΝΗΣΕΙΣΘΑΛΗΣ 2012 ΕΚΦΩΝΗΣΕΙΣ
ΘΑΛΗΣ 2012 ΕΚΦΩΝΗΣΕΙΣ
 

Semelhante a exercise-week-2-core-c-progr

Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docx
rosemarybdodson23141
 
09 a1ec01 c programming and data structures
09 a1ec01 c programming and data structures09 a1ec01 c programming and data structures
09 a1ec01 c programming and data structures
jntuworld
 
Computing_Year 10_Track 1_Student Paper.pdf
Computing_Year 10_Track 1_Student Paper.pdfComputing_Year 10_Track 1_Student Paper.pdf
Computing_Year 10_Track 1_Student Paper.pdf
raheeema suleman
 
Cs141 mid termexam v1
Cs141 mid termexam v1Cs141 mid termexam v1
Cs141 mid termexam v1
Fahadaio
 
Module wise format oops questions
Module wise format oops questionsModule wise format oops questions
Module wise format oops questions
SANTOSH RATH
 
Examf cs-cs141-2-17
Examf cs-cs141-2-17Examf cs-cs141-2-17
Examf cs-cs141-2-17
Fahadaio
 

Semelhante a exercise-week-2-core-c-progr (20)

Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docx
 
Computer science ms
Computer science msComputer science ms
Computer science ms
 
09 a1ec01 c programming and data structures
09 a1ec01 c programming and data structures09 a1ec01 c programming and data structures
09 a1ec01 c programming and data structures
 
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
 
CS Sample Paper 1
CS Sample Paper 1CS Sample Paper 1
CS Sample Paper 1
 
Redo midterm
Redo midtermRedo midterm
Redo midterm
 
Computing_Year 10_Track 1_Student Paper.pdf
Computing_Year 10_Track 1_Student Paper.pdfComputing_Year 10_Track 1_Student Paper.pdf
Computing_Year 10_Track 1_Student Paper.pdf
 
Java exercise1
Java exercise1Java exercise1
Java exercise1
 
Cs141 mid termexam v1
Cs141 mid termexam v1Cs141 mid termexam v1
Cs141 mid termexam v1
 
Sample paper
Sample paperSample paper
Sample paper
 
Cpcs 203 -array-problems
Cpcs 203 -array-problemsCpcs 203 -array-problems
Cpcs 203 -array-problems
 
Fy secondsemester2016
Fy secondsemester2016Fy secondsemester2016
Fy secondsemester2016
 
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
 
DAC CCAT GUESS PAPER Jun-Jul 2013
DAC CCAT GUESS PAPER Jun-Jul 2013 DAC CCAT GUESS PAPER Jun-Jul 2013
DAC CCAT GUESS PAPER Jun-Jul 2013
 
Pcd201516
Pcd201516Pcd201516
Pcd201516
 
CAPE Computer Science Unit 1 Paper 1 - Practice Paper
CAPE Computer Science Unit 1 Paper 1 - Practice PaperCAPE Computer Science Unit 1 Paper 1 - Practice Paper
CAPE Computer Science Unit 1 Paper 1 - Practice Paper
 
Module wise format oops questions
Module wise format oops questionsModule wise format oops questions
Module wise format oops questions
 
Computer science sqp
Computer science sqpComputer science sqp
Computer science sqp
 
Examf cs-cs141-2-17
Examf cs-cs141-2-17Examf cs-cs141-2-17
Examf cs-cs141-2-17
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
 

Último

Reconciling Conflicting Data Curation Actions: Transparency Through Argument...
Reconciling Conflicting Data Curation Actions:  Transparency Through Argument...Reconciling Conflicting Data Curation Actions:  Transparency Through Argument...
Reconciling Conflicting Data Curation Actions: Transparency Through Argument...
Bertram Ludäscher
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
HyderabadDolls
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
nirzagarg
 
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
gajnagarg
 
Gartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxGartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptx
chadhar227
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
gajnagarg
 
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
nirzagarg
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
gajnagarg
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
ahmedjiabur940
 

Último (20)

Aspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - AlmoraAspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - Almora
 
Reconciling Conflicting Data Curation Actions: Transparency Through Argument...
Reconciling Conflicting Data Curation Actions:  Transparency Through Argument...Reconciling Conflicting Data Curation Actions:  Transparency Through Argument...
Reconciling Conflicting Data Curation Actions: Transparency Through Argument...
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
 
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
 
Dubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls DubaiDubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls Dubai
 
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
 
Gartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxGartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptx
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
 
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
 
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
 
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
 
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With OrangePredicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
 
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
 
Statistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbersStatistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbers
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
 

exercise-week-2-core-c-progr

  • 1. HaNoi University of Technology Week 2:Core C# Programming Constructs – Mastering C# 2008 Week 2: Core C# Programming Constructs Topics • Constants & Variable • Statements and Expressions • Control Flow PART I: C # BASIC Exercise 1 Which letters represent valid identifiers? a) Abc e) $$$ i) a_1 b) M/H f) 25or6to4 j) Student Number c) Main g) 1_time k) string d) double h) first-Name Valid identifiers are ______________________________________________ Invalid identifiers are ____________________________________________ Exercise 2 using System; class Class1 { static void Main() { const int y = 1,z = 2; const string x = "Hello"; string X = "World"; Console.WriteLine(y + z); Console.WriteLine(x + " " + X); Console.ReadLine(); } } 2.1 What is written by this program? 1/6
  • 2. HaNoi University of Technology Week 2:Core C# Programming Constructs – Mastering C# 2008 2.2 List all variables in this program. Exercise 3 using System; class Class1 { static void Main() { const int b=a+1; //1 const int d=c+3; //2 const int c=b+2; //3 const int a=1; //4 Console.WriteLine(a + b + c + d); Console.ReadLine(); } } 3.1 From this program, when compiled, there are some errors. Why? 3.2 This program can be corrected by rearrangement of lines (1) to (4). Rewrite CONSTANT DECLARATION PART of this program to correct it. ________________________ ________________________ ________________________ ________________________ 2/6
  • 3. HaNoi University of Technology Week 2:Core C# Programming Constructs – Mastering C# 2008 Exercise 4 static void Main() { string s = "abc"; //1 int n = 0; //2 double x = 0.0; //3 s = n; //4 n = 1.0; //5 n = x; //6 x = 999; //7 x += n; //8 s = "abc" + 1; //9 s -= 1; //10 n = 1 + 1.5; //11 } In which line of this program (4-11) did errors occur? Line The problem is … 3/6
  • 4. HaNoi University of Technology Week 2:Core C# Programming Constructs – Mastering C# 2008 PART II: Operators and Priorities Precedence Order Operator 1 () 2 ++(x),--(x),+(x),-(x) 3 *,/,% 4 +,- 5 =,+=,-=,*=,/=,%= 6 (x)++,(x)-- Exercise 5 class Test { static void Main() { double x = 3.0, y = 2.0; int a = 10, b = 2; (1) Console.ReadLine(); } } Insert the line numbered (1) using instructions from the following table. Fill the column output. (1) Output Console.WriteLine(x+a); Console.WriteLine(a/b); Console.WriteLine(y/x); Console.WriteLine(y%x); Console.WriteLine(++y%x-1); Console.WriteLine(y--%x+1); Console.WriteLine(a+b%b); Console.WriteLine(x/y*b); Console.WriteLine((a+b)/b%a); Console.WriteLine(9.0/5.0*(a-x)); Console.WriteLine(x+y-x*y%x); Console.WriteLine(57%50/25); 4/6
  • 5. HaNoi University of Technology Week 2:Core C# Programming Constructs – Mastering C# 2008 PART III: Control Flow Exercise 6 class IfElseStruct { static void Main() { int x = 15; int y=20 ; if(x>y)Console.WriteLine(x); else Console.WriteLine(y) ; Console.ReadLine(); } } What is written from this program? Exercise 7 class ForStruct { static void Main() { for(int i=1 ;i<10 ;i++){ Console.WriteLine(i*i); } Console.ReadLine(); } } What is written from this program? Exercise 8 using System; { class WhileStruct 5/6
  • 6. HaNoi University of Technology Week 2:Core C# Programming Constructs – Mastering C# 2008 { static void Main() { int n=10; while(true){ if(n>0){ Console.WriteLine(n); n--; } else break; } Console.ReadLine(); } } } What is written from this program? Exercise 9 using System; { class Foreach { static void Main() { int[] A={10,9,8,7,6,5,4,3,2,1}; foreach(var x in A){ Console.WriteLine(x); } Console.ReadLine(); } } } What is written from this program? 6/6
  • 7. HaNoi University of Technology Week 2:Core C# Programming Constructs – Mastering C# 2008 { static void Main() { int n=10; while(true){ if(n>0){ Console.WriteLine(n); n--; } else break; } Console.ReadLine(); } } } What is written from this program? Exercise 9 using System; { class Foreach { static void Main() { int[] A={10,9,8,7,6,5,4,3,2,1}; foreach(var x in A){ Console.WriteLine(x); } Console.ReadLine(); } } } What is written from this program? 6/6