Skip to main content

Posts

Write a program in foxpro to generate fibonacci series.

                            Ans:- Input"Enter the last term of fibonacci series:-"to num a=0 b=1 i=1 ?a do while(i<=num) c=a+b a=b b=c ?a i=i+1 enddo

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); }