Tuesday 20 November 2012

C program code for reverse number using function with while loop

 C program code for reverse number using function with  while loop

how to write code to reverse given number in c program using function with comments
#include<stdio.h>  //including header files
#include<conio.h>
long int reverse(long int); // declaring function with parameter
void main()    // start main
{
 long int n;
 clrscr();
 printf("enter the value \n"); // asking for enter the value
 scanf("%ld",&n); // taking value from user
 printf("result=%ld",reverse(n));  //calling function
 getch();
 }
long int reverse(long int a)  // intialization of function
{
 int r;
 long int s=0;
 while (a != 0)  // checking number will not zero
 {
  r=a%10;    
  s=10*(s+r);
  a=a/10;
  reverse(a);  // reversing number
  }
 return (s/10); //returning reversed number
 }
c programming example  for reverse number using function with  while loop

c program factorial number using function.

c program  factorial number  using function.

Take two for loop .first for loop for one to last .
till we want to factorial and second will calculate factorial of each number.
factorial means multiplication of numbers.
example
factorial of 5 is 5*4*3*2*1=120.
so factorial of 5 is 120.
same for 6 is 6*5*4*3*2*1=720.



#include<stdio.h>
#include<conio.h>
long int fact( int*);
void main()
{
  int n;
  clrscr();
  printf("enter the value \n");
  scanf("%d",&n) ;
  printf("result=%ld",fact(&n)) ;
  getch();
  }

 long int fact(int* a)
 {
 long int f=1,sum=0;  //initialization of sum=0 and variable f =1.
 int i,j;
 for(i=1;i<=*a;i++) //execution of for loop
 {
  for(j=1;j<=i;j++) // second for loop
  {
  f=f*i;
  }
  f=i/f;
  sum=sum+f;
  }
  return sum; // will return the factorial of given number.
  }


programming examples for  factorial number  using function

how to draw concentric circles with help of while loop

how to draw concentric circles with help of while loop

concentric  circles which share same axis ,center and origin.
so sphere and disks are concentric circle we can assume.

#include<graphics.h> //graphic shows header file for design in c language.

main()
{
    int gd=DETECT,gm;
    int n,x=10;
    initgraph(&gd,&gm," ");
    printf("How many concentric circles do you want?");//asking for number of circle want to draw.
    scanf("%d",&n);
    while(n!=0)
    {
    circle(240,150,x);
    setcolor(GREEN);// setting color as green.
    x+=10;
    n--;
    }
    getch(); // end of main
    closegraph();
}
programming examples for concentric circles

Array | single dimensional array in c | c# | java | using for loop

Array | single dimensional array in c | c# | java | using for loop

How to print single array value.
array similar datatype collection.
declaration | initialization


int[] arr = new int[3];
    arr[0] = 1;
    arr[1] = 2;
    arr[2] = 3;
    Response.Write(arr[2]);
ptint second  value in array;

    int[] arr = new int[]{ 1, 2, 3, };
    for (int i = 0; i < arr.Length; i++)
    {
        Response.Write(arr[i]);
        Response.Write("<br>");
    }

   
    string[] arr = new string[4]{"hi","how","are","u"};
    for (int i = 0; i < arr.Length; i++)
    {
        Response.Write(arr[i]);
        Response.Write("<br>");
    }
in place of response.write c programmers can write "printf".
in java "System.out.println". this example shows array with int and string data-type

Multidimensional Array | two dimensional array c | c# | java |2*2 | 3*3 examples code

Multidimensional Array | two dimensional array c | c# | java |2*2 | 3*3 examples code

how to use array to perform or to write or to create structure of matrix.
declaration of array using for loop ,initialization of array using for loop.
how to create 2/2 or 3/3 array in simple programming language

creation of 2/2 array which will appear like matrix.

        int[,] arr = new int[2,2]
       
                                {
                                {1, 2,3 } ,
                                {4, 5 ,6},
                               
                               
                                };
        for (int i = 0; i <2; i++)
        {
            for (int j = 0; j<2; j++)
            {
             
                Response.Write((arr[i,j]));
                             
               
            }
            Response.Write("<br>");

        }
 

creation of 3/3 array
       
        int[,] arr = new int[3,3]
                                {
                                {1, 2,3 } ,
                                {4, 5 ,6},
                                  {889, 9 ,93},
                               
                                };
        for (int i = 0; i <3; i++)
        {
            for (int j = 0; j<3; j++)
            {
             
                Response.Write((arr[i,j]));
                             
               
            }
            Response.Write("<br>");

        }
 


printing of 2/3 array using for loop.
 int[,] arr = new int[2,3]
                                {
                                {1, 2,3 } ,
                                {4, 5 ,6},
                               
                               
                                };
        for (int i = 0; i <2; i++)
        {
            for (int j = 0; j<3; j++)
            {
             
                Response.Write((arr[i,j]));
                             
               
            }
            Response.Write("<br>");

        }
response.write use in asp.net to print array so if you want to print in c language just use printf.
whereas in   java it is system.out.println

Sunday 18 November 2012

N-tier | 3-Three | Architecture in asp.net with c# | sql server | insert | display.

N-tier | 3-Three |  Architecture in asp.net with c# | sql server | insert | display.
3-Three | N-tier | Architecture in asp.net with c# | sql server | insert | display. 1->Application layer 2->Database Layer 3->Business layer 4->Entity Layer 1->Application layer Mark up code:-
code Behind/Application layer

using System;
using System.Data.SqlClient;

using asp.netconnectionwith_class.connection;
namespace asp.netconnectionwith_class
{ 
    public partial class _Default : System.Web.UI.Page
    {
         connection.business objBl = new connection.business();
        connection.entity ObjEl = new connection.entity();
protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        protected void btninsert_Click1(object sender, EventArgs e)
        {
         
           int id = Convert.ToInt32(txtid.Text.Trim());
           string nm =Convert.ToString(txtname.Text.Trim());
             
            int i = 0;
            i = objBl.insertintotable(id,nm);
            if (i > 0)
            {
                Response.Write("value inserted succesfully");
            }
            else
            {
                Response.Write("Error in insertion");
            }


        }

        protected void btndisplay_Click(object sender, EventArgs e)
        {

            int i = 0;
            DataSet dt;
            dt =objBl.display();
            i = dt.Tables[0].Rows.Count;
            if (i > 0)
            {
                grdvw.DataSource = dt;
                grdvw.DataBind();
            }
            else
            {
                Response.Write("Error");
            }
          
        
        }
    }
}


business Layer


using System;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Web;

using asp.netconnectionwith_class;
using asp.netconnectionwith_class.connection;

namespace asp.netconnectionwith_class.connection
{
    
    public class business

    {
        connection.addconnection Objcon = new connection.addconnection();
       
        public DataSet  display()
        {
           
            SqlConnection con;
            con = Objcon.Dbconnection();  
            try
            {
                SqlCommand cmdin = new SqlCommand("dispvalue", con);
                cmdin.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter dAd = new SqlDataAdapter(cmdin);
                DataSet dSet = new DataSet();
                con.Open();
                dAd.Fill(dSet);
                return dSet;//.Tables["stud_info"];when use datatable
            }
            catch
            {
                throw;
            }
            finally
            {
                con.Close();
            }

        }
                       
        public int insertintotable(int id , string nm)
        {
            SqlConnection str;
            str = Objcon.Dbconnection();  

            int i = 0;
            try
            {
                str.Open();
                SqlCommand insertcommend = new SqlCommand("insertintotable", str);
               insertcommend.CommandType = CommandType.StoredProcedure;
               insertcommend.Parameters.AddWithValue("@id",id);
                insertcommend.Parameters.AddWithValue("@stud_nm",nm);
              
              
                i = insertcommend.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            finally
            {
                
                str.Close();
            }
            return i;
        }
    }
}


Entity layer

using System;
using System.Data;
using System.Web;


using asp.netconnectionwith_class;

namespace asp.netconnectionwith_class.connection
{
    public class entity
    {

       public int _id;
        public int id
        {
            get
            {

                return this._id;
            }
            set
            {
                this._id = value;
            }
        }
       public  string _nm;
        public string nm
        {
            get{return this._nm;}
            set{this._nm= value;
            }
        }
    }
}


DataBase Layer

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Data.SqlClient;

using System.Web.UI.WebControls.WebParts;


namespace asp.netconnectionwith_class.connection
{
  
    public class addconnection
    {
        public SqlConnection  Dbconnection()
        {
          
            SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["stud"].ConnectionString);
            return con;
        }

       
    }
}
IF you are using entity layer then it will be ntier else three tier architecture for connectivity in asp.net programming with c#. for understanding three tier architecture you need to create .cs file or we can say create class file in simple asp.net page.

c program Addition of two number using function with comments

c program Addition of two number  using function with comments

How to add two number using function in c language.
first include header files .
 This program is simple program in c language which is showing use of function to create in c  program and call that function for adding two numbers .in simple method we can do also but , by using function it makes easier .

#include<stdio.h> // header files

void main()    //start of main
{ //opening of main
  int first_number,second_number;      //declaration of two variable later which will store the values
  clrscr();
  printf("\n Enter 2 Number:"); //asking for enter the numbers
  scanf("%d %d",&first_number,&second_number);        //taking two numbers and storing  into variable first_number and second_number.
  printf("\Addition=%d",add(first_number,second_number));   calling function add()
}   //closing of main


  int add(int x,int y) //function add
  {
    return(x+y);   //will give addition of two numbers
  } // close function




how to use viewstate in vb.net | store value in viewstate

how to use viewstate in vb.net | store value in viewstate


view state we use for using data from one function to another function  on same  .aspx page.
we can also use session but it would create burden on server .
because ViewState is client side state management so , after use once it would be destroyed.
won't create burden on server.
we can use same type of idea in c# and vb.net . so , even syntax is same.
    ViewState("definevaluewherewewanttostoreviewstatevalue") = thevaluewewanttostore

    Protected Sub buttonbind_Click(ByVal sender As Object, ByVal e As EventArgs) Handles buttonbind.Click
        Dim sql As String = "select * from stud"
        Dim cmd As SqlCommand = New SqlCommand(sql, con)
        Dim da As New SqlDataAdapter(cmd)
        Dim dt As New DataTable
        da.Fill(dt)
        Dim ds As New DataSet
        ds.Tables.Add(dt)
        Dim sql1 As String = "select * from stud where id=1"
        Dim cmd1 As SqlCommand = New SqlCommand(sql1, con)
        Dim da1 As New SqlDataAdapter(cmd1)
        Dim dt1 As New DataTable
        da1.Fill(dt1)
        ds.Tables.Add(dt1)
        ViewState("ds") = ds  'storing dataset values into ds variable.

    End Sub

    Protected Sub buttondiaplsy_Click(ByVal sender As Object, ByVal e As EventArgs) Handles buttondiaplsy.Click
        Dim dsdisplay As New DataSet
        dsdisplay = ViewState("ds") 'storing ds variable value onto another variable in another buttonclick event.

    End Sub