Learn the powerful enterprise adaptable database:

Getting Started With ADABAS & Natural

Tuesday, December 16, 2014

Learn Basic C Sharp Programming


---
Learn Basic C# Programming
1) Hello World Program      
2) Sum Numbers Program      
3) Sum Variables Program      
4) Multiply Variables Program      
5) Divide Variables Program      
6) Count Numbers Program      
7) Display Array Values Program      
8) Edit Array Values Program      
9) Modular Program
       
1) Hello World Program
-----
Flow Chart:
https://docs.google.com/drawings/d/1GwGEoXoJ5vdqfZ-m6wlRBU3SItKvQCo5ER4EexcUebE/pub?w=198&h=214
-----
Pseudo Code:
1. BEGIN
2. PRINT "Hello World"
3. END
-----
C# Language sample code:
MyHello
using System;
public class MyHello
{
        public static void Main()
        {
                Console.WriteLine("Hello World");
        }
}
-----
Live code at ideone.com:http://ideone.com/Jn4QK9 
-----
C# Language sample output:
http://i.imgur.com/Vw2PSml.png
2) Sum Numbers Program
-----
Flow Chart:
  https://docs.google.com/drawings/d/13fOX0OUJBaprpfGbqAn2damRsFY_kzY6OhZ-5Bxrtgs/pub?w=193&h=218
----
Pseudo Code:
1. BEGIN
2. PRINT 1 + 2
3. END
-----
C# Language sample code:
MySum
using System;
public class MySum
{
        public static void Main()
        {
                Console.WriteLine(1+2);
        }
}
-----
Live code at ideone.com:http://ideone.com/LWBkge 
-----
C# Language sample output:
http://i.imgur.com/XfvlWgs.png
3) Sum Variables Program
-----
Flow Chart:
https://docs.google.com/drawings/d/1k4p-pIRxWMC7wtiIuWtWFy6C8BMBJXxTAVKJSfBBqYI/pub?w=192&h=299
-----
Pseudo Code:
1. BEGIN
2. INPUT var1var2
3. PRINT var1+var2
4. END
-----
C# Language sample code:
MySumVar
using System;
public class MySumVar
{
        public static void Main()
        {
                int var1 = Convert.ToInt32(Console.ReadLine());
                int var2 = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine(var1+var2);
        }
}
-----
Live code at ideone.com:http://ideone.com/Ao0wxg
-----
C# Language sample output:
http://i.imgur.com/VR9bDcU.png
4) Multiply Variables Program
-----
Flow Chart:
https://docs.google.com/drawings/d/15PKB_S3AcpovVu_cLxtdzsPUojM5s8e9UqaLizsKJ5k/pub?w=192&h=299
-----
Pseudo Code:
1. BEGIN
2. INPUT var1var2
3. PRINT var1 x var2
4. END
-----
C# Language sample code:
MyMultiplyVar
using System;
public class MyMultiplyVar
{
        public static void Main()
        {
                int var1 = Convert.ToInt32(Console.ReadLine());
                int var2 = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine(var1*var2);
        }
}
-----
Live code at ideone.com:http://ideone.com/Kb4Vha 
-----
C# Language sample output:
5) Divide Variables Program
-----
Flow Chart:
https://docs.google.com/drawings/d/15y5ajeirNjHfKYy0iiKwQMbP0-p4b3PdZq7XyZuemI4/pub?w=412&h=447
-----
Pseudo Code:
1. BEGIN
2. INPUT var1var2
3. IF var2=0
4. THEN PRINT "Error. Division by zero."
5. ELSE PRINT var1/var2
6. END
-----
C# Language sample code:
MyDivideVar
using System;
public class MyDivideVar
{
        public static void Main()
        {
                double var1 = Convert.ToDouble(Console.ReadLine());
                double var2 = Convert.ToDouble(Console.ReadLine());
                if (var2==0){Console.WriteLine("Error. Division by zero");}
                else{Console.WriteLine(var1/var2);};
        }
}
-----
Live code at ideone.com:http://ideone.com/2sm4Ec
-----
C# Language sample output:
http://img203.imageshack.us/img203/2195/lgta5e5.png
6) Count Numbers Program
-----
Flow Chart:
https://docs.google.com/drawings/d/19X-6x-gxS19xnIpEwgSYBVX1i8cTF5-8GWIn0cWb6OE/pub?w=412&h=447
-----
Pseudo Code:
1. BEGIN
2. PRINT "Start counting."
3. FOR i LOOP := 1 to 3
4.     PRINT i
5. END LOOP
6. PRINT "Done."
7. END
-----
C# Language sample code:
Note:array index number starts with 0.
MyCounter
using System;
public class MyCounter
{
        public static void Main()
        {
                Console.WriteLine("Start Counting.");
                for(int i=0;i<3;i++){
                Console.WriteLine(i);
                }
                Console.WriteLine("Counting Done.");
        }
}
-----
Live code at ideone.com:http://ideone.com/iZZAGY 
-----
C# Language sample output:
http://i.imgur.com/Br0Qg2a.png
7) Display Array Values Program
-----
Flow Chart:
-----
Pseudo Code:
1. BEGIN
2. INITIALIZE ARRAY arr[5] TO CONTAIN VALUES a,b,c,d,e
3. PRINT "Displaying array values."
4. FOR i := 1 to 5
5.    PRINT arr[i]
6. END FOR LOOP
7. PRINT "Done."
8. END
-----
C# Language sample code:
MyArray
using System;
public class MyArray
{
        public static void Main()
        {
                string[] arr={"a","b","c","d","e"};
                Console.WriteLine("Displaying array values.");
                for(int i=0;i<5;i++){
                Console.WriteLine(arr[i]);
                }
                Console.WriteLine("Done.");
        }
}
-----
Live code at ideone.com:http://ideone.com/MNKqBx
-----
C# Language sample output:
8) Edit Array Values Program
-----
Note:
This tutorial demonstrates the steps to edit an array value. The program displays the array values before and after the edit is done.
-----
Flow Chart:
https://docs.google.com/drawings/d/1p4RxgOXP5o9kp_YYGN1Zrf-COViepPv5eCOICcNPtAo/pub?w=414&h=1014
-----
Pseudo Code:
1. BEGIN
2. INITIALIZE ARRAY arr[i] WITH VALUES 1,2,3,4,5
3. FOR := 1 to 5
4.   PRINT arr[i]
5. END FOR LOOP
6. INPUT indexnumber
7. INPUT arrayvalue
8. arr[indexnumber] = arrayvalue
9. FOR i := 1 to 5
10.   PRINT arr[i]
11. END FOR LOOP
12. END
-----
C# Language sample code:
MyArrayUpdate
using System;
public class MyArrayUpdate
{
        public static void Main()
        {
                string[] arr={"a","b","c","d","e"};
                Console.WriteLine("Displaying array values.");
                for(int i=0;i<5;i++){
                Console.WriteLine(arr[i]);
                }
                Console.WriteLine("Done.");
                int indexNumber = Convert.ToInt32(Console.ReadLine());
                string arrayValue = Console.ReadLine();
                arr[indexNumber]=arrayValue;
                Console.WriteLine("Displaying array values.");
                for(int i=0;i<5;i++){
                Console.WriteLine(arr[i]);
                }
                Console.WriteLine("Done.");                
        }
}
-----
Live code at ideone.com:http://ideone.com/2ziONE 
-----
C# Language sample output:
9) Modular Program
-----
Flow Chart:
https://docs.google.com/drawings/d/1gZb3ypOmM5KXjyD1MZb_A6Hjg-H5_dSogGklL7vf9uo/pub?w=441&h=1283
-----
Pseudo Code:
1. BEGIN displaydata
2.   FOR all item in array PRINT item values
3. END displaydata
1. BEGIN updatedata
2.   INPUT indexnumber, arrayvalue
3.   arr[indexnumber]=arrayvalue
4.   CALL displaydata
4. END updatedata
1. BEGIN main
2.   CALL displaydata
3.   CALL updatedata
4. END main
-----
C# Language sample code:
MyModule
using System;
public class MyModule
{
        public static void Main()
        {
                string[] arr={"a","b","c","d","e"};
                displayData(arr);
                updateData(arr);
                displayData(arr);
        }
        private static void displayData(string[] arr1){
                Console.WriteLine("Displaying array values.");
                for(int i=0;i<5;i++){
                Console.WriteLine(arr1[i]);
                }
                Console.WriteLine("Done.");                        
        }
        private static void updateData(string[] arr2){
                int indexNumber = Convert.ToInt32(Console.ReadLine());
                string arrayValue = Console.ReadLine();
                Console.WriteLine("Updating...");        
                arr2[indexNumber]=arrayValue;                
        }
}
-----
Live code at ideone.com:http://ideone.com/mwFgoJ
-----
C# Language sample output:
-----
---

No comments:

Post a Comment