Sunday, May 24, 2015

Compare Between Array And Structure

Compare Between Array And Structure


Array
  •        I.            An Array is the collection of related data element of same types.
  •      II.            An Array is a derived data types.
  •   III.            An Array behaves like a built in data type we can declared array variables and uses it.
  •   IV.            Array allocates static memory and use index subscript for accessing elements of array. Structure allocates Dynamic memory and used operator for accessing the member of structure.
  •     V.            An array behaves like a built in data types All we have to do is to declare an array variable and use it.
  •   VI.            Array name is the pointer to the 1st elements of its.
  • VII.            Data type (int, Char, Etc) keyword is used to define Array.
  • VIII.            Eg ( Int a[50].

Structure
  •        I.            A Structure have a element of different types
  •      II.            A structure is a user define type.
  •   III.            First we have to define an structure and then declare the variable of that type.
  •   IV.            Structure name is not pointer.
  •     V.            Struct  keyword is used.
  •   VI.            Each member of structure is assigned its own unit storage. It takes more memory space then of union.
  • VII.            All the member of Structure can be access at any time at any point of time.
  • VIII.            EG

Struct S {
Char a;
Int i;
}
St;

Monday, May 18, 2015

what is Do-While loop

what is Do-While loop
It is also exit control loop. The condition is checked after executing the body of loop. That means the loop will be executed at least once.Do while loop is similar to while loop,however there is once basic difference do while run atleast once even if the test condition if false.Do-while loop is also called exit controlling loop.The condition comes after the body . Even the condition is false initially.
Syntax :-
                {
                                Statement;
                                Statement;
                                Increase/decrement;
                }
                While (condition);<semi column is needed.

Let us take one example to print square of even number from 1 to 50.
                Int main()
{
                Int i= 1;
                Do
                {
                If (i%2 == 0)
                {
                Printf(“%d/t”,i*i);
                }
                i+I;
                }
                While (i<=50);
                Return (0);
                }

Write to check input number is palindrome or not.
                Int main ()
{
                Int n , i , s=0, r;
                Printf(“enter any number “);
                Scant( “%d”, & n);
                N1 = n;
                Do
                {
                R = n % 10;
                N = n / 10;
                S = s*10 + r;
                If (s==n1)
Printf(“palindrome”);
Else
Printf(“nor palindrome”);
}
While (n!= 0);
Return(0);
}


Friday, May 15, 2015

Looping

Looping 
Looping
It is the process of executing (running) block of statement more than one times until some condition is made. Looping is a process of repeaed the activities unitl the operation is reached. Mainly we can categorized loop into two types:- on the basic of control.
1.       Entry control loop
2.       Exit control loop

1 . Entry control loop is checked at the beginning of loop or before executing block of statement of loop. If the condition is false initially, the loop cannot be executed even one times. (0 times).
Mainly there are two types of entry control loop in c programming.
(1)    For () loop
(2)    While () loop
Example :-
Write a program to display number from 1 to 100 by using for loop.
                Int  main()
{
                Int I;
For ( i= 1; i<=100; i++)
     {
                Printf(“%d/t”,i);
                }             
 Return (0);
}
2 . Exit control loop is checked at the end of the loop or end of the block of statement of loop. If the condition is initially false, the loop will be executed at once, do-while is the example of exit control loop.
Let us take one example:-
                Int main ()
{
                I = 10;
        do
                {
                                Printf(“Cambridge university”);
                   }
     While (i<5);
The Cambridge university is printed at once while.          
                  

While loop


LOOP:--
Loop Is Define as computer programming sequence of instruction that is continually repeated until a certain condition reached. if the condition has reached to the first instruction then loop repeated the sequence. The result of loop is repeated continually until the operation is success.
 While loop is also use for repeating block of statement in the programming until some condition is made. In case of while loop initialization is written before while condition is written inside while & increment /decrements is written inside while loop. It is used for both expected & unexpected ending.
Syntax :-
                Initialization;
                While (condition)
                { …………………;
                  ………………….;
                  ………………….;
                Increment/decrement;
                }

Example :-
                Write a program to display natural number from 1-100.
                                Int main()
                {
                                Int i = 1;
                                While (i < = 100);
                                {
                                Printf(“%d/t”,i);
                                i++;
                                retrun(0);
                                }

                Write a program to display even  number from 10-100.
                                Int main
                {
                                Int i = 10;
                                While (i < = 100);
                                {
                                If(i%2==0)
                                Printf(“%d is even ”,i);
                                i++;
                                retrun(0);
                                }

Write a program to display all upper case alphabet A-Z.
                                Int main
                {
                                Char ch = ‘A’
                                While(ch < = ‘Z’)
                                {
                                Printf(“%c/t”, ch);
                                Ch ++;
                                Return(0);
                                }



Write a program to display your name as many as time the user press y.
                                Int main
                {
                                Char ch = ‘Y’
                                While(ch = = ‘Y’ // ch == ‘Y’)
                                {
                                Printf(“Michal”);
                                Printf(“/n Do You want to continus Y/n”);
                                Scant(“%C”, & ch);
}
                                Return(0);
                                }


Wednesday, May 13, 2015

Write a program to read the number until -1 is in encountered, count the sum & negative, positive & zero.

Write a program to read the number until -1 is in encountered, count the sum & negative, positive & zero.


Int main ()
{
Int, n, p=0, ne=0, z=0;
Printf(“/n enter any number -1 to exit );
Scanf (“% d”, & n);
Do
   {
                Printf(“enter any no”);
                Scanf(“ % d” , & n);
                If (n < 0)
                Ne ++;
                Else if (n>0)
                P ++;
                Else
                Z ++;
                Printf(“ entry any no”);
                }
Print (“ no. of negative number =% d, no. of positive No= % d, no. of zero number = % d,ne , p , z);
                 While (n! = -1);
}
Return(0);
                }

Tuesday, May 12, 2015

Tokens

Tokens
The  Collection of a valided character set in “C” is called token.
Types of Tokens
·         Keyword
·         Identity
·         Constant
·         String constant
·         Operation
Example:
·         Keyword :- It is predefine word in the library we cannot change it during the programming.
                Eg:- int, float, char, long, double, switch, case, break, auto, else, if, for etc.

·         Identifiers :- It can define as a programmer define element like the name of variables, function, arrays. Rules for naming the identifiers :-
1 .  An identifiers is any combination of alphabetic digit or underscore.
Eg:- int a@ (*)  int a# (*)

2 . The first character In the identifier name must be an alphabet.
               
3 . No, comma or blanks space are allowed with an identifier.

4 . Length of the identifier depend upon complier.

5 . No special symbol other that under score can used.

6 . Upper case & lower case are dishing.

7 . A keyword cannot be used as a identifier.

8 . Identifier should be unique. Same identifier name cannot repeated with in a scope.

·         Constant :- It can be categorized in two types. It value doesn’t change during the programming.
 Type of Constant :-
1 . Literal constant :-   Directly used constant value is called literal constant.
2 . Symbolic constant :- Rether than using direct value we can created symbol to the literal constant by using # define directive before main () is called symbolic constant

A Basic Programming on C++

Write a program to display your name on screen.
#includ<stdio.h>
#include<conio.h>
                Int main()
{
                Clrscr():
Prntf(“MY NAME IS MICAHL FEDAR”);
getch();
Return(0);
                }

Write a program to find out the area of circle.
                Int main () Name of the declaration.
{
                Fioat a,r; //variable declaration.
                r=1.0; //initialization.
                 a=3.14*r*r; //calcualton.

 Output
a=3.14000000
 
Printf(“a=%f”,a);
getch();
return(0);
                }




Write to find out the area of cylinder.
a=2rh
                int main()
{
Float  a,r,h;
r=1.0;
h=1.0;
a=2*3.14*r*h;
print(“a=%f”,a);
getch();
return(0);
                }

Write to find out volume of cylinder. 



                Int main()
{
                Flot  r,h,v;
Print(“enter radius & height”)
Scanf(“%f%f”, & r & h);
V=3.14*r*r*h:
Printf(“volume=%f”,v);
                Getch();
                Return(0);
                }



Write a program to take input in KG. Convert it into a Grams
                Int main()
{             
                Float kg;
                Int. , gram
                Printf(“enter weight in KG”);
                Scantf(“%f”,&k);
                g=1000*k;
printf(“weighting in gram =%d”,g);
                getch();
                return(0);

                }

Array Program

ARRAY OF STRUCUTURE 
1.       Struct employee
{
Char name [20];
Int empid;
Float salary;
} emp [10];

2.       Struct employee
{
Char name [20];
Int empid;
Float salary;
};

Struct employee emp[10];


Write a program to created a structure name student that has name, roll no., marks & remarks as member, used this structure to read & display record of 5 std.

Struct student
{
Char name [50], remarks[10];
Int rollno;
Float marks;
};
Main()
{
Struct student std[5];
Int I;
For (i=0; i<5; i++)
{
Printf(“in enter %d student date”, i+1);
Printf(“name”);
Gets(std [i], name);
Printf(“rollno”);
Scanf(“%d”, &std[i]. rollno);
Printf(“remarks”);
Gets(std[i].remark);
Printf(“marks”);
Scanf(“%f”, &std [i]. mark);
}
Printf(“name\+ rollno\ + remarks\ + mark|n”);
For(i=0; i<5; i++)
Printf(“%s\t%d\t%s\t%f”, std[i].name, std[i].rollno, std[i].remarks, std[i].marks);
}
Getch();
}








Friday, May 8, 2015

C++


Write to read name of 10 student & display them in dictionary order.

#include<stdio.h>
#include<conio.h>
                Main()
{
                Char a [10][20], t[20];
                Int I;
                /* Reading 10 string */
                For (i=0; i<10; i++)
                {
                Printf(“in enter %d string”, i+1);
                Gets(a[i]);
                }
                For (i=0; i<9; i++)
                {
                For (j=i+1; J<10; j++)
                {
                If (stremp (a[i], a[j]) >0)
                {
                Strcpy(t, a[i]);
                Strcpy(a[i], a[j]);
                Strcpy(a[j], t);
                }
                }
]



Read name roll no, total marks of a student & display.
                Struct s
                {
                Char name [50];
                Int roll no;
                Float marks[50];
                }stu;
                Main()
                {
                Printf(“in enter name”);
                Gets(Stu.name);
                Printf(“\n enter roll no”);
                Scanf(“%d” , & enter roll no);
                Printf(“\n enter percentage”);
                Scanf(“%f”, &stu. Per);

                /* display  data */
               
                Printf (“in name= %C, roll no =% d, percentage =%f, stu.name, stu,=.roll no, stu.per);
                Getch();
                }




Copying  a structure.

Write a program to reads name roll no. marks of 5 subject of a student copy to the next structure variable & display.

#include<stdio.h>
#include<conio.h>
Struct s
{
Char name [50];
Int roll no;
Float m[5];
}
Main ()
{
Struct s stu, b;
Int i;
Printf(“enter name”);
Gets(stu.name);
Printf(“enter roll no”);
Scanf(“%d”, & stu.roll no);
For(i=0; i<5; i++)
{
Printf(“in enter % d subject mark”, i+1);
Scanf(“%f”, stu. M[i]);
}

/* copying structure */

  B=stu;
Printf(“in name =%s”, b.name);
Printf(“in roll no=%d”,b.rollno);
For (i=0; i<5; I++)
Printf(“in %f”, b.m[i])
}







Structure Initialization
  Struct student
{
Char name[20];
Int rollno;
Float marks;
};

Struct student st{“Harry”, 10, 56.5};
This line is equivalent to
                Struct student st;
                St. name =’Harry”;
                St. rollno = 100;

                St. ,marks = 56.5;

Write a program to read name rollno. Mark in 5 subject of a student and display name, Percentage and division of a student?

Write a program to read name rollno. Mark in 5 subject of a student and display name, Percentage and division of a student?

Add caption

include<stdio.h>
include<conio.h>
Struct S {
                Char name [50];
                Int rollno;
                Float m[5];
                };
Main()
                { FILE
                Struct s stud;
                Float per tot=0;
                printf(“Enter name”);
                gets(stu.name);
                printf(“Enter rollno”);
                scanf(“%d”, & stu.rollno);
                for(i=o; i<5; i++)
                 {
                 Printf(“\n Enter %d Subject Mark”, i+1);
                Scanf(“%f”, & stud.m[i]);
                Tot=tot+stud.mark[i];
}


/*      Display    */

Printf(“\n name =%s”, Stud.name);
Printf(“\n Percentage=%f “, per);
If(per>=75)
Printf(“Distinction”);
Else if (per>=65)
Printf(“1st Division”);
Else if(per>=50)
Printf(“2nd Division”);
Else
Printf(“Fail”);
Getch();

}

Saturday, May 2, 2015

What is Program?

What is Program?
The set of instructions which command the computer to perform particular operation or a specific task is called a program.
Program is written in a programming language then translated into machine code by a language processor so that the computer can execute task. The programming language statements are the source program or source code and this object code is linked with other library codes to create the program. A program is composed of list of instructions to perform a specific job. An instruction is also called statement. It is independent of its own and it is created by a programmer. Program cannot be categorized according to needs and uses. Generally, a statement is an instruction to do only one task.
                For example
                #include<stdio.h>
                #include<conio.h>
                Void main()
                {
                                Int n;
                                Clrscr();
                                Printf (“Input a number to check if is even or odd :”);
                                Scanf(“%d”,&n);
                                If(n%2==0)
                                                Printf(“%d is even”,n);
                                Else
                                                Printf(“%d is odd”,n);
                                getch();

Qualities of Good Program
A program can be considered as a good program, they are:
Ø  It should be correct. It should not contain error.
Ø  It should be efficient in terms processing and memory utilization.
Ø  It should have easier user interface.
Ø  It should be easy to maintain and update.
Ø  It should be flexible.
Ø  It should be reliable.
Ø  It should be portable.
Ø  It should be easy to understand.