- Upvotes Received
- 1
- Posts with Upvotes
- 1
- Upvoting Members
- 1
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
25 Posted Topics
Hi all, I have a minor confusion regarding the variable accessed Consider: [CODE] int a=5; //global variable void increment(int a) { ++a; } [/CODE] If I call increment() in main(), which a will be incremented (a passed as a parameter to the function or the global a ?) Also specify … | |
Hi, the following is the code for returning the position of a substring within a string(Brute force algorithm) [CODE] //Brute Force Algorithm #include<stdio.h> #include<string.h> int main(void) { char s1[20],s2[10]; int x1,x2,j,k,i; printf("Enter string 1:"); gets(s1); printf("Enter string 2:"); gets(s2); x1=strlen(s1); x2=strlen(s2); if(x1<x2) return 0; for(i=0;i<=x1-x2;i++) { j=i; k=0; while((s1[j]==s2[k])&&k<x2) { … | |
I am trying to find out inorder successor of a node in a binary search tree. I read the algorithm from "Introduction to Algorithms,Cormen" and understood it. But the problem I face is that I can't find out the parent of the node when it is needed in the algorithm. … | |
Hi all, I am trying to code iterative implementation of bst. But I am encountering some problems as the stack is not updated as it should be. I am getting incorrect output.Some suggestions would be welcomed. [CODE] /*Operations to be performed:- ->Insertion ->Deletion ->Modification ->Search ->Minimum ->Maximum ->Predecessor ->Successor ->Inorder … | |
Hi all, I have a doubt regarding finding a loop in a linked list.I searched on internet and found 2 different ways of doing the same. But my doubt is that if a linked list has a loop, then wouldn't it be a circular linked list? If yes, then the … | |
Hello all, I am third year student pursuing computer science engineering and I want to develop a software which can be coded in C and includes integrating it with database for data. I really need help for some ideas which are new(I need to develop something which is original or … | |
I have the following code for converting a list of t infix expressions into their postfix form:- [CODE] #include<stdio.h> #include<string.h> #include<ctype.h> #define MAX 400 struct stack { char arr[MAX]; int top; }; void initstack(struct stack *); void push(struct stack *,char); char pop(struct stack *); void convert(struct stack *s,char *); int … | |
I have the following code for Quick Sort procedure: [CODE] #include<stdio.h> void Quick_sort(int *arr,int left,int right); int Partition(int *arr,int left,int right,int pivotindex); int main() { int a[20],n,ctr=0,j=0; printf("\nEnter number of elements:"); scanf("%d",&n); printf("Enter array elements:"); while(ctr<n) { scanf("%d ",&a[ctr]); ctr++; } Quick_sort(a,0,n-1); printf("\nSorted Array:"); while(j<n) { printf("%d ",a[j]); j++; } … | |
Consider the error in following program- [CODE] #include<stdio.h> #include<conio.h> #define MAX 100 struct stacktype { int stack[MAX]; int top; } ; void push(struct stacktype * s,int item) { if(s->top==MAX-1) { printf("Overflow"); return; } s->top++; s->stack[s->top]=item; } int pop(struct stacktype *s) { int item; if(s->top==-1) { printf("UnderFlow"); return -1; } item=s->stack[s->top]; … | |
Re: Gerard4143 is right. You need a variable to store the value of i(the day on which temperature was maximum) i.e. [CODE] if(Max<Day[i]) { Max = Day[i]; k=i; } [/CODE] Then you can print k as the day on which temperature was maximum. Also use [CODE] int i,Day[7],Temp; [/CODE] instead of … | |
I have written the following code for converting infix to prefix.. [CODE] //Infix to prefix conversion #include<stdio.h> #include<conio.h> #include<string.h> #include<ctype.h> #define MAX 25 void initstack(struct stack *); void push(struct stack *,char); char pop(struct stack *); char *convert(struct stack *,char *); void show(struct stack); int priority(char); struct stack { char arr[MAX]; … | |
This is my code for drawing a circle using mid point algorithm:- [CODE] //Midpoint circle algorithm #include<graphics.h> #include<stdio.h> #include<conio.h> void drawcircle(int xc,int yc,int r); int main() { int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"..//bgi"); drawcircle(250,250,10); getch(); return 0; } void drawcircle(int xc,int yc,int r) { int p,x=0,y=r,incr1=2*x+3,incr2=incr1+2-2*y; void drawPixel(int,int,int,int); drawPixel(xc,yc,x,y); p=1-r; while(x<=y) { if(p<0) … | |
I have the following code for DDA Line Algorithm in C :- [CODE] //DDA Line Algorithm #include<stdio.h> #include<graphics.h> #include<conio.h> #include<math.h> #include<stdlib.h> #define Round(a) ((int)(a+0.5)) void linDDA(int xa,int ya,int xb,int yb); int main() { int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"E:\\TC\\bgi"); linDDA(10,20,200,100); clrscr(); getch(); return 0; } void linDDA(int xa,int ya,int xb,int yb) { int … | |
I have the following function to delete nodes in a doubly linked list at a specified position [CODE]void Delete(struct dnode **ptr,int pos) /*pos refers to position at which element is to be deleted and ptr is the pointer to the first node in the list */ { struct dnode *temp; … | |
Re: One good website is Cracktheinterview.org which has some tricky problems on all the topics of C really useful for interviews and logic building. | |
Hi, I have the code to add elements at the end of the linked list using recursion. [CODE] //Adds an element at end using recursion #include<stdio.h> #include<conio.h> #include<stdlib.h> struct node { int data; struct node *link; }; void addatend(struct node **,int); void display(struct node *); int main() { struct node … | |
Hi, I want to know which function can be used for inputting a number of lines in C? | |
I found the following code on internet for adding two numbers using pointers:- [CODE] #include<stdio.h> int main() { int a=30000,b=20,sum; char *p; p=(char *)a; sum= (int)&p[b]; printf("%d",sum); return 0; } [/CODE] But I can't understand how p holds the value 30000 or how the result of the program is addition … | |
Hi coders,I have a small problem regarding pointers, I am a bit weak in pointers and need to understand why the following is wrong: [CODE] int main(void) { char *a; gets(a); return 0; } [/CODE] This causes an exception, please explain the error. I am using Turbo C as compiler, … | |
Hi, I have the following code which compiles absolutely fine.. [CODE] using namespace std; #include<iostream> #include<stdio.h> #include<conio.h> struct node { int data; struct node *link; }; void add(struct node **,int); void display(struct node*); int count(struct node *); int main(void) { struct node *p; p=NULL; add(&p,5); add(&p,1); add(&p,6); add(&p,4); add(&p,7); display(p); … | |
Hi, I have the following code which compiles fine but does not produce any output.. [CODE] using namespace std; #include<iostream> #include<cstdio> #include<conio.h> struct node { int data; struct node *link; }; void append(struct node *,int); void addatbeg(struct node *,int); void addafter(struct node *,int,int); void display(struct node *); int count(struct node … | |
I have a problem in which we are given 2 sets A and B and we have to find set C which contains elements common to A and B.The set A and B can contain duplicates and set C is expected to contain distinct elements(i.e no repetition of the same … | |
I have the following code to find first and second largest elements of an array: [CODE] using namespace std; #include<iostream> #include<conio.h> #include<cstdio> #include<string.h> int* create(int); int maximum(int *,int); int second_max(int *,int); void freememory(int*); int main(void) { int *p,size; cout<<"Enter size of the array:"; cin>>size; p=create(size); cout<<"\nMaximum elemnt in the array … | |
Hi.. I am new to Dani web and would like to know the problem in the following code: [CODE] #include<iostream.h> #include<conio.h> void insertion_sort(int *p); int main() { int a[20],j; cout<<"\nEnter contents of array:"; for(int k=0;k<20;k++) { cin>>a[k]; } insertion_sort(a); return 0; } void insertion_sort(int *p) { int h,key; for(int i=2;i<20;i++) … | |
Hi,I am new to daniweb and would like to know the error in this code [CODE] void initpoly(struct poly *p) { int i; p->noofterms=0; for(i=0;i<MAX;i++) { p->t[i].coeff=0; p->t[i].exp=0; } }[/CODE] I am not posting the entire program because it is lengthy.I am getting the error"Expected primary expression before token ;" … |
The End.