Skip to main content

Posts

Showing posts with the label Technical and programming

Write a data structure program to make an array as stack.

Ans:- #include<stdio.h> #define MAX 10 int st[MAX],top=-1; void push(int st[],int val); int pop(int st[]); void display(int st[]); int main() { int val,option; do { printf("\n *****MAIN MENU*****"); printf("\n 1. PUSH"); printf("\n 2. POP"); printf("\n 3. DISPLAY"); printf("\n 4. EXIT"); printf("\n***************"); printf("\n enter your option:"); scanf("%d",&option); switch(option) { case 1: printf("\n Enter the number to be pushed on the stack:"); scanf("%d",&val); push(st,val); break; case 2: val = pop(st); if(val!=-1) printf("\n The value deleted from the stack is:%d",val); break; case 3: display(st); break;   } } while(option!=5); getch(); return 0; } void push(int st[],int val) { if(top==MAX-1) { printf("\n STACK OVERF...

Write a program to operate on linked list.All possible operation are performed through separate functions.

#include<stdio.h> #include<malloc.h> struct node { int data; struct node *next; }; struct node *start=NULL; struct node *create_11(struct node *); struct node *display(struct node *); struct node *insert_beg(struct node *); struct node *insert_end(struct node *); struct node *insert_before(struct node *); struct node *insert_after(struct node *); struct node *delete_beg(struct node *); struct node *delete_end(struct node *); struct node *delete_node(struct node *); struct node *delete_after(struct node *); struct node *delete_list(struct node *); struct node *sort_list(struct node *); int main() { int option; do { printf("\n\n *****MAIN MENU*****"); printf("\n1:Create a list"); printf("\n2:Display the list"); printf("\n3:Add a node at the beginning"); printf("\n4:Add a node at the end"); printf("\n5:Add a before a given node"); printf("\n6:Add a node after a g...

4.) With argument and With return

In this type of function arguments and parameters must be passed to any function and function return a single value.The type of function depends up on the return value. syntax:- datatype of function name(datatype arg 1,datatype arg2) { statement; ........... ........... return(exp); }                   ex:-main() { int fact(int); printf("\n factorial =%d",fact(5)); getch(); } int fact(int n) { int f=1; while(n>1) { f=f*n; n--; } return(f); }

3.) No argument and with return

In this type of function,parameter and argument are not passed to any f\unction and function must return a value.So the datatype of function depends up on the datatype of return value of the function. syntax:- datatype function name() { statement; .......... ................ return(exp); }               * Ex:- void main() { int x; int sum(); x=sum(); printf("\n sum=%d",x); getch(); } int sum() { int a,b,c; printf("\n enter two number"); scanf("%d%d",&a,&b); c=a+b; return(c); }

2.) With argument and No return

In this type of function argument and parameter must be specified and function doesn't return any value so the datatype of function must be "void" syntax:- void function name(datatype arg 1,datatype arg 2) { statement; ......... .......... } example:-write  a program to input 3 number and calculate sum using function with argument and no return.           Ex:- void main() { int a,b,c; void sum(int,int,int); printf("\n enter three number"); scanf("%d%d%d",&a,&b,&c); sum(a,b,c); getch(); } void sum(int x,int y,int z) { int add; add=x+y+z; printf("\n sum of three number=%d",add); }

Type of user defined function.

1.)No argument and no return 2.)With argument and no return 3.)No argument and with return 4.)With argument and with return               1.)No argument and no return In this type of function,there is no argument and function doesn't return any value.So,the datatype of the function must be "void" syntax:- void function name() { statement; .......... ........ } for example:- write a program to input two number by the keyboards and calculate sum using function no argument and no return. void sum() { int s,a,b; printf("\n enter two numbers"); scanf("%d%d",&a,&b); s=a+b; printf("\n sum=%d",s); } void main() { sum(); getch(); }

#Advantage of function.

                    To define user defined function in our program file at the top of the main() function or below of the  main function.It can't be defined in the body of main function. user defined function can be written in to a saperate file also. syntax:- datatype function name (argument with data type) {    statement; ................... ................. ................. return(exp); } :- Were datatype of a function depends up on the datatype of return value by the function. :-The rule of function name is same as the rule of variable name. :-Argument is also called parameter.The variable name or name are declared with in the paranthesis() of a function is called arguments. Note :- If a function doesn't return any function the data type of function is void(null datatype). In c language it is optimal.

#What is function?

A Function is a self contained sub program that is meant to do some well defined task. A function is also called procedure,subroutine,subprogram.It is suitable set of instruction which performs a task is called function.In another word small module of program is called function. * Type of function There are two type function 1.)Inbuilt/predefined/library function printf() scanf() clrscr() getchar() getch() putchar() strcmp() etc... 2.) User defined function:- The user can create there own function for performing any specific task. Three thing required to create user defined function are:- a.) function definition b.)function prototype c.)function call    

What is Increament or decrement operator?

They are (++) increment operator in c. (--)decrement operator in c. These two operators are called unary operator as they require only one operand.The operand should be a variable not a constant. * (++) operator :- Add one to the value of operand. *(--) operator :- substract one to the value of operand. # These operators are used in two form 1 pastfix form 2 prefix form          

What is OPERATOR?

An operator is a special symbol that tells the computer to perform certain mathematics or logical maniculation on data stored in variables.The variables that are operated are turned as operands. C operates can be classified in to following categories :- 1 Arithmetic operator 2 Relational operator 3 Logical             " 4 Assignment        " 5 Increments or decrement operator 6 Conditional operator 7 Bit wise operator 8 Special operator              

4.What is variable?

A variable is an entity whose value can change during program execution.A variable is symbolic representation of address of the memory stress were values can be stored,excesed and changed. Each variable has a name and datatype.All variable must have their type indicated,so that the compiler can record all the necessary information about them,generate appropriate code during allocating required space in memory. # Rules for construction variable name:- 1 It should be a combination of alphabet,digits or under score. 2 First character must be an alphabet 3 Variable name should not be matching with reserve word in c Example:- Employ - name                         "            age                     Item- 4 etc ➡ A variable declaration in c is done as-type specified,separed list of separable  Ex- int,I,g,k        ...

3. What is Constant?

A constant is an entity with fixed value that doesn't change.It can be stored at a location in memory of the computer and can be reference through that memory addressed. ➡ Constant are fixed value that remain unchanged during the execution of programme and are used in assignment statement constant can be stored in variables. ✖ There are 5 basic types of constant in c 1 Integer constant 2 Real constant 3 character constant 4 String constant 5 Logical constant  

* Component of 'c' language

1 character set 2 Data type  3 Constant 4 Variable  5 Keywords  6 Grammar (syntax and semantic) 1 Character set :- All symbols used to write in c language.they are :-  a. Letter  (a-z,A-Z) B.Digits  (0-9) C.symbol  (*,&,+,-) D.White space :-Black space, horizontal tab,carriage return, new line etc.... 2 Data type :-Datatype is defining and attributes to the variable.It defining the set of legal that the variable can store.the basic data type int,char,float,etc.....    

What is computer programming/language?

C is a structured programming language.c language is developed in 1972 at bell laboratories by a system programming named Dennis rithcie. ➡ c comes between low level language and high level language ✖ Advantages of c programming language 1 c is a machine independent and highly portable language. 2 It is easy to learn and it has only 32 keywords. 3 It has comprehensive set of operator to tackle business as well as scientific application with ease. 4 All graphics programming as well as system programming can be implemented using c. 5 User can create their own function/facility and add them in c laboratories to perform a variety of tasks. 6 It has large libraries function. 7 C operates on the same datatype as the computer,so the code need very little data conversion.