1 / 33

char a[10] ; int num[20] ; num a int *b ;

اشاره گر ها Pointers. char a[10] ; int num[20] ; num a int *b ;. reverse(s) abcde edcba. int x; int *ip , *q; ip = &x ; *ip=0 ; *ip = *ip + 10 ; /* x = 10 */ *ip += 1 ; /* x = 11 */ ++*ip ; /* x = 12 */

avent
Download Presentation

char a[10] ; int num[20] ; num a int *b ;

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. اشاره گر ها Pointers char a[10] ; int num[20] ; num a int *b ;

  2. reverse(s) abcde edcba

  3. int x; int *ip , *q; ip = &x ; *ip=0 ; *ip = *ip + 10 ; /* x = 10 */ *ip += 1 ; /* x = 11 */ ++*ip ; /* x = 12 */ (*ip)++ ; /* x = 13 */ *ip++ ; *(ip++) ; q = ip ; from = line line = from ;

  4. y = y + 5 ; y += 5 ; z *= 20 ; t %= 6 ; t = t % 6 ; += -= *= /= %=

  5. اشاره گر ها Pointers int a[10]; a &a[0] *a a[0] char student_name[40]; student_name &student_name[0]

  6. int a[10] , x = 0; int *p1; a[1] a[0] a[9] a *a a[0] a[0] a a[1] a + 1 *(a + 1) a[1] a[i] a + i a[i] *(a + i) p1 = a; p1= &x;

  7. int strlen(char s[ ]) { int i; i=0; while( s[i] != ‘\0’) ++i; return i ; }

  8. hamid main() { char c ; char name[ ]=“hamid” ; c = *name character string كاراكتريرشته null 0 ‘\0’ ‘A’ “Hello , are you well today” c = *(name + 5) ; name name + 5 name + 1 string constant ثابت رشته اي

  9. #include <stdio.h> main() { char *p; char name[50]; p = “ What is your name?\n” /* printf(“ What is your name?\n”); */ printf(“%s” , p); scanf(“%s” , name); printf(“%s” , name); } 86-3-9 كد 102

  10. تابع scanf() ‘ ‘ و tab و newline را بعنوان جداكننده در نظر مي گيرد. لذا hamid rahimlu را 5 مي شمرد. #include <conio.h> #include <stdio.h> main() { int a, b , c ; clrscr(); scanf("%d%d%d" , &a , &b , &c ); printf("a = %d \t b = %d \t c = %d\n", a , b , c ); } نام برنامهscanf3.c C:\tc_current\Scanf3.exe <inputScanf3.txt از فايل ورودي مقادير a , b , c را مي خواند.

  11. ASCII EBCDIC

  12. Character arrays Enumeration Constants Recursive functions توابع بازگشتي

  13. char name[30] ; char array-name[ size ] ; ثابت رشته اي در آرايه كاراكتري ذخيره مي شود . string constant “Behnam Ahmadi” “#%^jkl123)({} “ “dsgvghsd\\ghh”

  14. int x = 5 ; مقدار اوليه دادن initialization main() int x ; --- --- x = 5 ; --- } scanf( “%d” , &x) ;

  15. char name[] = “Behnam Ahmadi” ; name[0] = ‘B’ name[1] = ‘e’ name[12] = ‘i’ Name[13] = ‘\0’ char name[] = “Behnam123” ; Name[6] = ‘1’ Name[7] = ‘2’ x = ( name[7] – ‘0’ ) * 7

  16. while ( there ‘s another line ) if ( it ‘s longer than the previous longest ) save it ; save it’s length print longest line

  17. It is a book There are 41 students in this class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

  18. #include <stdio.h> #define MAXLINE 1000 /* maximum input line length */ int getline(char line[ ], int maxline); void copy(char to[], char from[]); /* print the longest input line */ main() {

  19. /* print the longest input line */ main() { int len; /* current line length */ int max; /* maximum length seen so far */ char line[MAXLINE]; /* current input line */ char longest[MAXLINE]; /* longest line saved here */ max = 0; while ((len = getline(line, MAXLINE)) > 0) if (len > max) { max = len; copy(longest, line); } if (max > 0) /* there was a line */ printf("%s", longest); return 0; }

  20. /* getline: read a line into s, return length */ int getline(char *s,int lim) { int c, i; for (i=0; i < lim-1 && (c=getchar())!=EOF && c!='\n'; ++i) s[i] = c; if (c == '\n') { s[i] = c; ++i; } s[i] = '\0'; return i; } line

  21. /* copy: copy 'from' into 'to'; assume to is big enough */ void copy(char to[], char from[]) { int i; i = 0; while ((to[i] = from[i]) != '\0') ++i; } line longest

  22. x2 x >= 0 f(x) = -x3 x < 0

  23. #include <stdio.h> #include <math.h> double func1(double ) ; main() { double x ; scanf(“%lf” , &x ) ; printf(“f(%lf) = %lf “ , x , func1(x) ); }

  24. double func1( double x ) { if ( x >= 0 ) return pow( x , 2.0 ); else return -pow( x , 3.0 ) ; }

  25. حلقه Do-while : حلقه هاي for و while شرط خاتمه حلقه را ابتدا test مي كنند. لذا اگر شرط غلط باشد دستور يا دستوراتي كه بدنه حلقه را تشكيل مي دهند حتي يكبار هم اجرا نمي شوند. سومين حلقه C به نام do-while بعد از هر بار اجراي دستورات شرط را تست مي كند لذا بدنه حلقه حداقل يكبار اجرا مي شود. do statement ; while ( expression ) ; do { statement1; statementN; } while ( expression ) ; ابتدا statement اجرا مي شود سپس شرط بررسي مي شود. اگر شرط True باشد statement دوباره اجرا مي شود و بهمين ترتيب . اگر شرط غلط باشد از كل ساختار خارج مي شود.

  26. #include <stdio.h> /* strlen: return length of a string s */ تابعstrlen()int mystrlen( char *s) { int i = 0 ; while ( s[i] != ‘\0’ ) ++i ; return i ; } main() { printf( “ %d “ , mystrlen(“hello”) ); }

  27. #include <dos.h> #include <stdio.h> #include <conio.h> int mystrlen( char *s ); main() { char name[40]; clrscr(); scanf("%s" , name); sleep(3); printf( "\n %d " , mystrlen(name) ); sleep(7); /* wait for 7 seconds */ } /* strlen: return length of a string s */ int mystrlen( char *s) { int i = 0 ; while ( *( s + i ) != '\0' ) ++i ; return i ; }

  28. #include <dos.h> sleep( int sec) /* wait for specified seconds in sec */

  29. #include <stdio.h> #include <conio.h> #include <math.h> double polart(double t , double z ); double polarr(double , double ); main() { double x , y ; clrscr(); printf("x ? \n"); scanf("%lf" , &x); printf("y ? \n"); scanf("%lf" , &y); printf("r = %6.2f\n", polarr(x , y ) ) ; printf("tetha = %6.2f\n", polart(x , y ) ) ; }

  30. double polart(double x , double y ) { return atan2( y , x ); } double polarr(double x , double y) { return sqrt( pow(x , 2.0) + pow(y , 2.0) ) ; }

  31. #include <stdio.h> #include <conio.h> #include <math.h> void polar(double x , double y , double *pr, double *pt ); main() { double x , y , r , t ; clrscr(); printf("x ? \n"); scanf("%lf" , &x); printf("y ? \n"); scanf("%lf" , &y); polar( x , y , &r , &t ); printf("r = %6.2f\n", r ) ; printf("tetha = %6.2f\n", t ) ; }

  32. void polar(double x , double y , double *pr, double *pt ) { *pt = atan2( y , x ); *pr = sqrt( pow(x , 2.0) + pow(y , 2.0) ) ; return ; }

  33. pt pr x y x y polar main

More Related