You are on page 1of 5

What ‘s a computer program?

 It’s a collection of instructions that can be executed to perform a specific task.


 A program contains a list of values (called variables) and a list of directions (called statements) that tell
the computer what to do with the variables.
Examples:
1. Operating System
2. Web browser (chrome & firefox )
3. Microsoft word
4. Skype
5. Adobe acrobat

What’s Data structure?


 It’s a particular way of organizing data in a computer so that it can be used effectively.
 It’s a group of data elements grouped together under one name. these data elements known as members
and lengths.

Benefits of data structure?


 Formal data structures enable a programmer to mentally structure large amounts of data into
conceptually manageable relationships.
 Allow us to accomplish fast searching or sorting of data.
Note  Anything can store data can be called data structure.

Types of Data Structure?

Data structure

primitive/ complex/ user-


built-in DS defined DS

Integer Arrays Lists

Float Linear List Non-Linear List

Character stack Tree

Queue graph
What’s Algorithm?
 It’s a logical sequence of direct steps that describe a solution to a given problem in a finite amount of
time.
 It’s a finite set of instructions or logic, written in order to perform a certain predefined task.

C# Syntax and structure


A c# program Consists of the following parts:
1- Namespace declaration
2- A class
3- A main method(function)
4- Statements
5- Variables
6- Comments
Note The starting point of the program is Main method
 The method put inside a class
 A class may be put inside a namespace
 A namespace is a container of classes
.‫ ﻣﺨﺘﻠﻔﮫ‬namespaces ‫ ﺑﻨﻔﺲ اﻻﺳﻢ ﻟﻜﻦ ﻓﻲ‬class ‫ اﻧﻚ ﺗﻘﺪر ﺗﻌﻤﻞ اﻛﺘﺮ ﻣﻦ‬namespace ‫اﻟﮭﺪف ﻣﻦ ال‬

Variables:
Variables
Types

Floating
Integers strings Boolean
points

byte float char bool


(1byte) (4byte) (1byte) (true/false)

short double
string
(2byte) (8byte)

int (4 byte)

long
(8byte)
<data type > <variable name> ;
Ex:
int radius;
double area;
int a, b,c ;
bool is_okay;

noteC# is case-sensitive

comments:
// single line comment

/*
Multi-line
comment
*/

Output statements:
Console.Write(“welcome”); ‫ھﻨﺎ ﺑﻌﺪ ﻣﯿﻄﺒﻊ ھﯿﻔﻀﻞ اﻟﻤﺆﺷﺮ ﻓﻲ ﻧﻔﺲ اﻟﺴﻄﺮ‬

Console.WriteLine(“heeeey”); ‫ﺑﻌﺪ ﻣﯿﻄﺒﻊ ھﯿﻨﺰل اﻟﻤﺆﺷﺮ ﻟﻠﺴﻄﺮ اﻟﺘﺎﻟﻰ‬

Input statements:
Console.ReadLine(); ‫ﺑﺘﺮﺟﻊ ﺑﻨﺺ‬
string name = Console.ReadLine();
(int, double, float,…….) ‫ ﻻﺑﺪ ﻣﻦ ﺗﺤﻮﯾﻠﮫ ﻟﺮﻗﻢ أي‬string‫ﻟﻮ اﻟﻤﺴﺘﺨﺪ ھﯿﺪﺧﻞ رﻗﻢ ﺑﺎﻟﺘﺎﻟﻰ اﻟﺮﻗﻢ ھﯿﻜﻮن ﻣﻦ ﻧﻮع‬
int x = int.Parse(Console.ReadLine()); ‫ﻟﻮ ﻋﺎوز ﺗﺤﻮل اﻟﻨﺺ ﻟﺮﻗﻢ ﺳﻮف ﻧﺴﺘﺨﺪم اﻻﻣﺮ اﻟﺘﺎﻟﻰ‬
String Format :
string myName = “sally”;

Console.WriteLine(“I am ” + myName); //I am sally

Console.WriteLine(“I am {0}” , myName); //I am sally

Console.WriteLine($ “I am { myName }”); //I am sally


Example1: Write a program to enter the student name and his degree in 3 subjects then print the average.
Static void main(){
string name;
double d1,d2,d3,av;
Console.WriteLine(“Enter ur name: ”);
name = Console.ReadLine();
Console.Write(“Enter first degree : ”);
d1 = double.Parse(Console.ReadLine());
Console.Write(“Enter second degree : ”);
d2 = double.Parse(Console.ReadLine());
Console.Write(“Enter third degree : ”);
d3 = double.Parse(Console.ReadLine());
av = (d1+ d2+ d3)/3;
Console.WriteLine( name + “ his average degree = ” + av);
}

You might also like