cs lecture oct 28

cs lecture oct 28 - int main(void) { int i=6; int...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
cs lecture oct 28 Question 10 999 …………………………………0 [][][][][][][][][][][][][][][][][][2] [][][][][][][][][][][][][][][][][][][][][][][] -> x2 , carry over #include <stdio.h> int main(void) { int I,j; int d[1000]={0}; d[0]=1; for (i=0;i<1000;i++) for(int j=0; i<1000;j++){ d[j]*=2; if(d[j]>=10) d[j+1]+=1; d[j]-=10; } } for( i=0;i<1000;i++){ j+=d[i]; printf(“%d\n”,j); } Pagerank important points -fixed point iteration(idea) struct link{ int src, dst; } struct link e[]={{0,1}.{0,2},{2,1},{1,0}};
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
struck link l0[]={{0,2,},{0,1},{1,2},{3,0},{2.3}}; Pointers (see chapter 11/12) int i=6; 0[][][] 4[ ] 8[ ] x[ 6-> 10 ]i [ ] [ ] [ ] [ ] [ ] [ ] [ ] int main(void){ int i=6; int *p=&i; *p=10; *p: access the int that p points to printf(“%d\n”,i); =>10 return 0; } Pointer Assignment
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int main(void) { int i=6; int *p=&I; int *q; q=p; *q=17; printf(%d]n,i); 17 return 0; } q[ ] i[17 ] p [ ] int **z=&p; pointer to a pointer Pointers as arguments (ch 11, ex 4 swap values) #include <stdio.h> void swap(int*p,int*q) { int temp=*p; *q=*p; *p=temp; } int main(void){ int i=1;j=2; swap(&I,&j); printf(%d\n,i); ->2 printf(%d\n,j); ->1 return 0; } Pointers as return results (ch 11, ex 8 return a pointer to the largest element of an array) int main(void) { int test={0,1,2,3,2,1,0}; int *p=largest(test,7); *p=100; printf(%d\n,test[3]); 100 return 0; } int *largest (int a, int n) { int I,m=0; for(i=0;i<n;i++) if(a[i]>a[m]) m-I; return&(a[m]); }...
View Full Document

This note was uploaded on 12/10/2011 for the course CS 137 taught by Professor Clarke during the Fall '10 term at Waterloo.

Page1 / 3

cs lecture oct 28 - int main(void) { int i=6; int...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online