Toplam 3 Sayfadan 1. Sayfa 123 SonuncuSonuncu
Toplam 26 sonuçtan 1 ile 10 arasındakiler gösteriliyor.

Konu: C örnekleri

  1. #1
    ER
    Üyelik tarihi
    May 2006
    Mesajlar
    73
    Forum Katkısı:
    0

    Standart C örnekleri

    Gecen donem aldığım bu dersin asistandan ornekleri alıp buraya ekliycem..inşallah işe yarar..

    /* Bu benim ilk programim */
    #include<stdio.h>
    int main(){
    printf ("This is my first program.\n"); // comment line
    return 0;
    }





    #include<stdio.h>
    int main() {
    int a;
    float b,c;
    a=5;
    b=7.6;
    c=a+b;
    printf("%d + %0.2f = %0.2f\n",a,b,c); /* a,b,c are printed out on the screen */
    return 0;
    }


    #include <stdio.h>
    /* This function adds two numbers and returns the result */
    float fonk_add( int x, float y ){
    float z;
    z = x + y;
    return z;
    }

    int main(){
    int a;
    float b, sum;
    a=5;
    b=12.50;
    sum = fonk_add( a, b); // sum = fonk_add( a, b)=z
    printf("The addition of %d and %0.2f is %0.2f\n", a,b,sum);
    return 0;
    }













    #include <stdio.h>
    /* This function adds two numbers and prints the result */
    void fonk_add( int x, float y ){
    float z;
    z = x + y;
    printf("From the function z = %.2f\n",z) ;
    }

    int main(){
    int a;
    float b;
    a=5;
    b=12.50;
    fonk_add( a, b);
    return 0;
    }

    #include <stdio.h>

    /* This function prints the message */
    void fonk_message(){
    printf("This is a message\n") ;
    }

    int main(){
    fonk_message();
    return 0;
    }


    #include <stdio.h>
    /* An integer number a is divided by a float number b
    numbers a and b are read from the standart input consecutively */

    float fonk( int x, float y ){
    float z;
    z = x / y;
    return z;
    }

    int main(){
    int a;
    float b, c;
    while(1){
    printf("Enter two numbers : integer a and float b ? : ");
    scanf("%d %f",&a,&b);
    c = fonk(a, b); // c = z
    printf(" %d / %0.2f = %0.2f \n", a,b,c);
    }
    return 0;
    }

    /* 04L01.c: Print out characters */
    #include <stdio.h>

    int main(){
    char c1;
    char c2;

    c1 = 'A';
    c2 = 'a';
    printf("Convert the value of c1 to character: %c.\n", c1);
    printf("Convert the value of c2 to character: %c.\n", c2);
    return 0;
    }
















    /* 04L02.c: Convert numeric values back to characters */
    #include <stdio.h>

    int main(){
    char c1;
    char c2;

    c1 = 65;
    c2 = 97;
    printf("The character that has the numeric value of 65 is: %c.\n", c1);
    printf("The character that has the numeric value of 97 is: %c.\n", c2);
    return 0;
    }



    /* 04L04.c: Floating-point operations */
    #include <stdio.h>
    int main(){
    int int_num1, int_num2, int_num3, int_num4; /* Declare integer variables */
    float flt_num1, flt_num2, flt_num3, flt_num4; /* Declare floating-point variables */
    int_num1 = 32 / 10; /* Both divisor and dividend are integers */
    flt_num1 = 32 / 10;
    int_num2 = 32.0 / 10; /* The divisor is an integer */
    flt_num2 = 32.0 / 10;
    int_num3 = 32 / 10.0; /* The dividend is an integer */
    flt_num3 = 32 / 10.0;
    int_num4 = 32.0 / 10.0;
    flt_num4 = 32.0 / 10.0;

    printf("The integer divis. of 32/10 is: %d\n", int_num1);
    printf("The floating-point divis. of 32/10 is: %f\n", flt_num1);
    printf("The integer divis. of 32.0/10 is: %d\n", int_num2);
    printf("The floating-point divis. of 32.0/10 is: %f\n", flt_num2);
    printf("The integer divis. of 32/10.0 is: %d\n", int_num3);
    printf("The floating-point divis. of 32/10.0 is: %f\n", flt_num3);
    printf("The integer divis. of 32.0 / 10.0 is: %d\n", int_num4);
    printf("The floating-point divis. of 32.0 / 10.0 is: %f\n", flt_num4);
    return 0;
    }

  2. #2
    ONBAŞI
    Üyelik tarihi
    Apr 2006
    Mesajlar
    199
    Forum Katkısı:
    0

    Standart C örnekleri

    teşekk&#252;rler
    [B][SIZE="5"][COLOR="White"]вєη нєя gєçєη güη çöz∂üğüηü ∂üşüη∂üğüη
    αмα αѕℓα çözємιує¢єğιη ρяσвℓємιм.
    ѕαğℓαмαм αѕℓα ∂σğяυ çıкмαz.
    вєηι çöz∂üğüηü ∂üşüη∂üğüη αη∂α
    нєρ єη вαşα gєяι ∂öηєяѕιη.[/COLOR][/SIZE][/B]

    Neyf-i Ebedi

  3. #3
    ACEMİ ER
    Üyelik tarihi
    Oct 2005
    Mesajlar
    3
    Forum Katkısı:
    0

    Standart C örnekleri

    saol kardeş devamını beklios &#231;ok iii olur walla başım belada bu c ile
    EY TÜRK TİTRE VE KENDİNE GEL!!!BU VATAN BİZİM..

  4. #4
    ASTEĞMEN
    Üyelik tarihi
    Mar 2006
    Mesajlar
    1,078
    Forum Katkısı:
    0

    Standart C örnekleri

    bu ne hız, foruma ilk adım, ilk mesajda paylaşım. Bu hızla gidersen mesaj sayın kadar konun olur.

  5. #5
    ER
    Üyelik tarihi
    May 2006
    Mesajlar
    73
    Forum Katkısı:
    0

    Standart C örnekleri

    o zaman devam edelim ileri orneklerle...

  6. #6
    ER
    Üyelik tarihi
    May 2006
    Mesajlar
    73
    Forum Katkısı:
    0

    Standart C örnekleri

    /* 04L03.c: Show numeric value of characters */
    #include <stdio.h>

    int main(){
    char c1,c2,c3;
    c1 = '?';
    c2 = '$';
    c3 = '\n';
    printf("The numeric value of ? $ \\n are %d %d %d.\n", c1,c2,c3);

    return 0;
    }

    /* 04L07.c: Reading a character from standart input by calling
    getc() and outputting the character by putc() and putchar() */
    #include <stdio.h>

    int main(){
    char ch;
    printf ("Enter a single character ? : ");
    ch=getc(stdin);
    putchar(ch);
    putchar('\n');
    putc(ch,stdout);
    putc('\n',stdout);
    printf("%c\n",ch);
    return 0;
    }


    /* 04L05.c: Reading a character from standart input by calling scanf()
    and printing out the character and its numeric value */
    #include <stdio.h>

    int main(){
    char ch;
    printf ("Enter a single character ? : ");
    scanf("%c",&ch);
    printf("The numeric value of %c is : %d.\n",ch, ch);
    return 0;
    }


    /* 04L06.c: Reading a character from standart input by calling getchar()
    and outputting the character by putchar() */
    #include <stdio.h>

    int main(){
    char ch;
    printf ("Enter a single character ? : ");
    ch=getchar();
    putchar(ch);

    putchar('\n');
    return 0;
    }


    /* 05prog3.c: Specify minimum field width and precision specifiers*/
    #include <stdio.h>
    int main(){
    int num1, num2;
    float num3;
    double num4 , num5 , num8;
    long double num6 ,num7;
    unsigned int num9;
    num1 = 12;
    num2 = 12345;
    num3 = 30.456789;
    num4 = 999999999999999.0;
    num5 = 0.123456789123456;
    num6 = 9223372036854775807;
    num7 = 0.12345678912345671;
    num8 = 9.567845e307;
    num9 = 4220000000;
    printf("%d %10d\n", num1,num2);
    printf("%5d %-5d %05d\n", num1,num1,num1);
    printf("%f %10.4f %.3f %10.2f\n", num3, num3, num3, num3);
    printf(" %20.1f %30.15f\n", num4, num5);
    printf(" %20.0Lf %30.17Lf\n", num6, num7);
    printf(" %e %E\n", num8, num8);
    printf(" %u \n", num9);
    return 0;
    }


    /* 06L01.c: Use arithmetic assignment operators */
    #include <stdio.h>

    int main(){
    int x, y, z;

    x = 1;
    y = 2;
    printf("Given x = %d, and y = %d,\n", x, y);
    x = x + y;
    printf("x = x + y assigns %d to x.\n", x);

    x = 1;
    printf("Given x = %d, and y = %d,\n", x, y);
    x += y; // x=x+y
    printf("x += y assigns %d to x.\n", x);

    x = 5;
    printf("Given x = %d, and y = %d,\n", x, y);
    x -= y; // x=x-y
    printf("x -= y assigns %d to x. \n", x);

    z = 10;
    printf("Given z = %d, and y = %d,\n", z, y);
    z /= y; // z=z/y
    printf("z /= y assigns %d to z.\n", z);

    z = 10;
    printf("Given z = %d, x = %d ,and y = %d,\n", z, x, y);
    z *= x + y; // z=z * (x + y)
    printf("z *= x + y assigns %d to z.\n", z);

    printf("Given x = %d ,and y = %d,\n", x, y);
    x %= y; // x=x%y
    printf("x %%= y assigns %d to x.\n", x);
    return 0;
    }


    /* 06L02.c: pre- or post-increment(decreement) operators */
    #include <stdio.h>

    int main(){
    int w, x, y, z, result;

    w = x = y = z = 1; /* initialize x , y, w, and z */
    printf("Given w = %d, x = %d, y = %d, and z = %d,\n", w, x, y, z);

    result = ++w;
    printf("++w gives: %d w=%d \n", result, w);

    result = x++;
    printf("x++ gives: %d x=%d \n", result, x);

    result = --y;
    printf("--y gives: %d y=%d \n", result, y);

    result = z--;
    printf("z-- gives: %d z=%d \n", result, z);
    return 0;
    }


    /* 06L03.c: Use relational operators ==, !=, >, <, >=, <= */
    #include <stdio.h>

    int main(){
    int x, y;
    double z;

    x = 7;
    y = 25;
    z = 24.5;
    printf("Given x = %d, y = %d, and z = %.2f,\n", x, y, z);
    printf("x >= y produces: %d\n", x >= y);
    printf("x == y produces: %d\n", x == y);
    printf("x < z produces: %d\n", x < z);
    printf("y > z produces: %d\n", y > z);
    printf("x != y - 18 produces: %d\n", x != y - 18);
    printf("x + y != z produces: %d\n", x + y != z);
    return 0;
    }

    /* 06L09.c: Use cast operator */
    #include <stdio.h>

    int main(){
    int x, y;

    x = 7;
    y = 5;
    printf("Given x = %d, y = %d\n", x, y);
    printf("x / y produces: %d\n", x / y);
    printf("(float)x / y produces: %.3f\n", (float) x / y);

    return 0;
    }

  7. #7
    ÇAVUŞ
    Üyelik tarihi
    Sep 2004
    Mesajlar
    383
    Forum Katkısı:
    0

    Standart C örnekleri

    kardeş bana c de yazılmış teknik servis programı lazım okul bitirme projelerimin arasında oda var eger bana yardımcı olabilirsen seviniirim &#246;zelden g&#246;r&#252;şelim...

    Bu arada adın İsmail ve ak&#246;rende okuyorsan &#246;zelden deyilde msndende g&#246;r&#252;şebiliriz


  8. #8
    ER
    Üyelik tarihi
    May 2006
    Mesajlar
    73
    Forum Katkısı:
    0

    Standart C örnekleri

    /* Use sin(), cos(), tan() functions */
    #include <stdio.h>
    #include <math.h>

    int main(){
    double x;
    x = 45.0; /* 45 degree */
    x *= 3.141593 / 180.0; /* convert to radians */
    printf("The sine of 45 is: %f.\n", sin(x));
    printf("The cosine of 45 is: %f.\n", cos(x));
    printf("The tangent of 45 is: %f. \n", tan(x));

    return 0;
    }


    /* 09L05.c: Use pow(), sqrt(), abs(), fabs(), exp(), log and log10 functions */
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>

    int main(){
    double x, y,m=2.0,n=-7.8 ;
    int z;
    x = 4.0;
    y = 3.0;z=-7;
    printf("The 4 x 4 x 4 is: %7.0f %.0f \n", pow(x, y),pow(4.0,3.0));
    printf("The 3th root of 8 is : %7.4f \n",pow(2*x,1/y));
    printf("The square root of 4 is: %2.0f %.0f \n", sqrt(x),sqrt(4));
    printf("The absulute value of -7 and -7.8 are: %d %.2f\n", abs(z),fabs(n));
    printf(" exp(1)=%f,exp(2)=%f,exp(3)=%f \n", exp(1),exp(2),exp(3));
    printf("exp(pow(2,2))=%f\n",exp(pow(m,2))) ;
    printf("log(100)=%f log10(100)=%f \n",log(100),log10(100));

    return 0;
    }



    /* Use the if statement */
    #include <stdio.h>

    int main(){
    int i;
    printf("Integers that can be divided by both 2 and 3\n");
    printf("(within the range of 0 to 100):\n");
    for (i=0; i<=100; i++)
    if ((i%2 == 0) && (i%3 == 0))
    printf(" %d\n", i);
    return 0;
    }


    /* Use the if statement */
    #include <stdio.h>

    int main(){
    int i;
    printf("Integers that can be divided by both 2 and 3\n");
    printf("(within the range of 0 to 100):\n");
    for (i=0; i<=100; i++)
    if ((i%2 == 0) && (i%3 == 0))
    printf(" %d\n", i);
    return 0;
    }



    /* Use nested if statements */
    #include <stdio.h>

    int main(){
    int i;

    for (i=-5; i<=5; i++){
    if (i > 0){
    if (i%2 == 0)
    printf("%d is an even number.\n", i);
    else
    printf("%d is an odd number.\n", i);
    }else if (i == 0)
    printf("The number is zero.\n");

    else
    printf("Negative number: %d\n", i);
    }
    return 0;
    }


    /* Break an infinite loop */
    #include <stdio.h>

    int main(){
    int c;

    printf("Enter a character:\n(enter x to exit)\n");
    while (1) {
    c = getc(stdin);
    if (c == 'x')
    break;
    }
    printf("Break the infinite while loop. Bye!\n");
    return 0;
    }


    /* Use the continue statement */
    #include <stdio.h>

    int main(){
    int i, sum=0;
    for (i=1; i<8; i++){
    if ((i==3) || (i==5))
    continue;
    sum += i;
    }
    printf("The sum of 1, 2, 4, 6, and 7 is: %d\n", sum);
    return 0;
    }


    #include<stdio.h>
    int main(){
    int i,j,x;
    x=0;
    for ( i=6; i >=2 ; i-=2 ){
    for ( j=i+1; j > 2 ; j-- ){
    if ( (i+j)%3!=0 )
    continue;
    else {
    x+=i+j;
    printf(" i+j=%d \n",i+j);
    }
    }
    }
    printf(" x=%d \n",x);
    return 0;
    }




    #include<stdio.h>
    int main(){
    int n,x,y;
    n=-15;x=0;y=0;
    while( n <= 25){
    while( n < 0 && n%3==0 ){
    printf(" %d \n",n);
    x+=n;
    break;
    }
    while( n > 0 && n%5==0){
    printf(" %d \n",n);
    y+=n;
    break;
    }
    n+=2;
    }
    printf(" x=%d y=%d\n",x,y);
    return 0;
    }


    #include <stdio.h>
    double fonk(int n1, int n2){
    int i;
    double sum=0;
    for (i=n1; i<=n2;i++){
    sum+=i;
    }
    return sum;
    }

    int main(){
    int n1,n2;
    while(1){
    printf("Enter two integer numbers n1 < n2: ");
    scanf("%d%d",&n1,&n2);
    if ( n1 > n2 ){
    printf("n1 should be smaller than n2. TRY AGAIN!... \n");
    continue;
    }
    printf("Toplam=%.0f\n", fonk(n1,n2) );
    }
    return 0;
    }

    /* 12L01.c: Initialize an array */
    #include <stdio.h>
    /*
    ARRAY LIST

    |---|---|---|---|---|---|---|---|---|----|
    | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
    |---|---|---|---|---|---|---|---|---|----|
    */
    int main(){
    int i;
    int list[10];
    for (i=0; i<10; i++){
    list[i] = i + 1;
    printf( "list[%d] is initialized with %d.\n", i, list[i]);
    }
    return 0;
    }



    /* 12L04.c: Print out an array of characters */
    #include <stdio.h>

    int main(){
    char array_ch[7] = {'H', 'e', 'l', 'l', 'o', '!', '\0'};
    int i;

    for (i=0; i<7; i++)
    printf("array_ch[%d] contains: %c\n", i, array_ch[i]);
    /*--- method I ---*/
    printf( "Put all elements together(Method I):\n");
    for (i=0; i<7; i++)
    printf("%c", array_ch[i]);
    /*--- method II ---*/
    printf( "\nPut all elements together(Method II):\n");
    printf( "%s\n", array_ch);

    return 0;
    }



    /* 12L05.c: Stop at the null character */
    #include <stdio.h>

    int main(){
    char array_ch[15] = {'C', ' ',
    'i', 's', ' ',
    'p', 'o', 'w', 'e', 'r',
    'f', 'u', 'l', '!', '\0'};
    int i;
    for (i=0; array_ch[i]; i++)
    printf("%c", array_ch[i]);
    printf("\n");
    return 0;
    }


    /* 12L06.c: Print out a 2-D array */
    #include <stdio.h>
    /*
    COL1 COL2 COL3 COL4 COL5

    |-----|-----|-----|-----|-----|
    ROW1 | 1 | 2 | 3 | 4 | 5 |
    |-----|-----|-----|-----|-----|
    ROW2 | 10 | 20 | 30 | 40 | 50 |
    |-----|-----|-----|-----|-----|
    ROW3 | 100 | 200 | 300 | 400 | 500 |
    |-----|-----|-----|-----|-----|
    */
    int main(){
    int two_dim[3][5] = { {1, 2, 3, 4, 5},
    {10, 20, 30, 40, 50},
    {100, 200, 300, 400, 500} };
    int i, j;
    for (i=0; i<3; i++){
    for (j=0; j<5; j++)
    printf("%6d", two_dim[i][j]);
    printf("\n");
    }
    return 0;
    }



    /* 12L07.c: Initialize unsized arrays */
    #include <stdio.h>

    int main()
    {
    char array_ch[] = {'C', ' ',
    'i', 's', ' ',
    'p', 'o', 'w', 'e', 'r',
    'f', 'u', 'l', '!', '\0'};
    int list_int[][3] = {
    {1, 1, 1},
    { 2, 2, 8},
    {3, 9, 27},
    {4, 16, 64},
    {5, 25, 125},
    {6, 36, 216},
    {7, 49, 343} };


    printf("The size of array_ch[] is %d bytes.\n", sizeof (array_ch));
    printf("The size of list_int[][3] is %d bytes.\n", sizeof (list_int));
    return 0;
    }


    /* 13L01.c: Initialize strings */
    #include <stdio.h>

    int main(){
    char str1[] = {'A', ' ',
    's', 't', 'r', 'i', 'n', 'g', ' ',
    'c', 'o', 'n', 's', 't', 'a', 'n', 't', '\0'};
    char str2[] = "Another string constant";
    int i;

    /* print out str1 */
    for (i=0; str1[i]; i++)
    printf("%c", str1[i]);
    printf("\n");

    /* print out str2 */
    for (i=0; str2[i]; i++)
    printf("%c", str2[i]);
    printf("\n");

    return 0;
    }


    /* 13L02.c: Measure string length */
    #include <stdio.h>
    #include <string.h>

    int main(){
    char str1[] = {'A', ' ',
    's', 't', 'r', 'i', 'n', 'g', ' ',
    'c', 'o', 'n', 's', 't', 'a', 'n', 't', '\0'};
    char str2[] = "Another string constant";

    printf("The length of str1 is: %d bytes\n", strlen(str1));
    printf("The length of str2 is: %d bytes\n", strlen(str2));

    return 0;
    }


    /* 13L03.c: Copy strings */
    #include <stdio.h>
    #include <string.h>

    int main(){
    char str1[] = "Copy a string.";
    char str2[15];
    char str3[15];
    int i;

    /* with strcpy() */
    strcpy(str2, str1);
    /* without strcpy() */
    for (i=0; str1[i]; i++)
    str3[i] = str1[i];
    str3[i] = '\0';
    /* display str2 and str3 */
    printf("The content of str2: %s\n", str2);
    printf("The content of str3: %s\n", str3);
    return 0;
    }



    /* 13L04.c: Use gets() and puts() */
    #include <stdio.h>
    int main(){
    char str[5];
    int i;
    printf("Enter a string ? : ");
    gets( str );
    // scanf("%s",str);
    i = 0;
    while (str[i]){
    if ((str[i] >= 97) && (str[i] <= 122))
    str[i] -= 32; /* convert to upper case */
    i++;
    }
    printf("The entered string is (in uppercase):\n");
    puts( str );
    // printf("%s\n",str);
    return 0;
    }


    #include<stdio.h>
    int fonk(int arr1[],int arr2[]){
    int i,s=0;
    for ( i = 0; i < 6 ; i++)
    if (arr1[i]%2==0)
    arr2[s++]= arr1[i];
    return s;
    }
    int main(){
    int n,i;
    int arr1[]={2,3,4,6,7,12};
    int arr2[10];
    n=fonk(arr1,arr2);
    for (i=0; i < n ; i++)
    printf("%3d ",arr2[i]);
    printf("\n");
    return 0;
    }


    #include<stdio.h>
    int main(){
    int i,j,s=0;
    int arr1[2][3]={{2,3,4},{6,7,12}};
    int arr2[10];

    for ( i = 0; i < 2 ; i++)
    for ( j = 0; j < 3 ; j++)
    if (arr1[i][j]%2==0)
    arr2[s++]=arr1[i][j];

    for (i=0; i < s ; i++)
    printf("%3d ",arr2[i]);
    printf("\n");
    return 0;
    }



    /* 11L01.c: Obtain addresses */
    #include <stdio.h>

    int main()
    {
    char c;
    int x;
    float y;

    printf("c: address=%p, content=%c\n", &c, c);
    printf("x: address=%p, content=%d\n", &x, x);
    printf("y: address=%p, content=%5.2f\n", &y, y);
    c = 'A';
    x = 7;
    y = 123.45;
    printf("c: address=%p, content=%c\n", &c, c);
    printf("x: address=%p, content=%d\n", &x, x);
    printf("y: address=%p, content=%5.2f\n", &y, y);
    return 0;
    }

    /* 11L02.c: Declare and assign values to pointers */
    #include <stdio.h>

    int main()
    {
    char c, *ptr_c;
    int x, *ptr_x;
    float y, *ptr_y;

    c = 'A';
    x = 7;
    y = 123.45;
    printf("c: address=%p, content=%c\n", &c, c);
    printf("x: address=%p, content=%d\n", &x, x);
    printf("y: address=%p, content=%5.2f\n", &y, y);
    ptr_c = &c;
    printf("ptr_c: address=%p, content=%p\n", &ptr_c, ptr_c);
    printf("*ptr_c => %c\n", *ptr_c);
    ptr_x = &x;
    printf("prt_x: address=%p, content=%p\n", &ptr_x, ptr_x);
    printf("*ptr_x => %d\n", *ptr_x);
    ptr_y = &y;
    printf("prt_y: address=%p, content=%p\n", &ptr_y, ptr_y);
    printf("*ptr_y => %5.2f\n", *ptr_y);
    return 0;
    }


    /* 11L03.c: Change values via pointers */
    #include <stdio.h>

    int main()
    {
    char c, *ptr_c;

    c = 'A';
    printf("c: address=%p, content=%c\n", &c, c);
    ptr_c = &c;
    printf("ptr_c: address=%p, content=%p\n", &ptr_c, ptr_c);
    printf("*ptr_c => %c\n", *ptr_c);
    *ptr_c = 'B';
    printf("ptr_c: address=%p, content=%p\n", &ptr_c, ptr_c);
    printf("*ptr_c => %c\n", *ptr_c);
    printf("c: address=%p, content=%c\n", &c, c);
    return 0;
    }


    /* 11L04.c: Pointing to the same thing */
    #include <stdio.h>

    int main()
    {
    int x=1234;
    int *ptr_1, *ptr_2, *ptr_3;


    printf("x: address=%p, content=%d\n", &x, x);
    ptr_1 = &x;
    printf("ptr_1: address=%p, content=%p\n", &ptr_1, ptr_1);
    printf("*ptr_1 => %d\n", *ptr_1);
    ptr_2 = &x;
    printf("ptr_2: address=%p, content=%p\n", &ptr_2, ptr_2);
    printf("*ptr_2 => %d\n", *ptr_2);

    ptr_3 = &x;
    printf("ptr_3: address=%p, content=%p\n", &ptr_3, ptr_3);
    printf("*ptr_3 => %d\n", *ptr_3);

    return 0;
    }

  9. #9
    ER
    Üyelik tarihi
    May 2006
    Mesajlar
    73
    Forum Katkısı:
    0

    Standart C örnekleri

    /* Use sin(), cos(), tan() functions */
    #include <stdio.h>
    #include <math.h>

    int main(){
    double x;
    x = 45.0; /* 45 degree */
    x *= 3.141593 / 180.0; /* convert to radians */
    printf("The sine of 45 is: %f.\n", sin(x));
    printf("The cosine of 45 is: %f.\n", cos(x));
    printf("The tangent of 45 is: %f. \n", tan(x));

    return 0;
    }


    /* 09L05.c: Use pow(), sqrt(), abs(), fabs(), exp(), log and log10 functions */
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>

    int main(){
    double x, y,m=2.0,n=-7.8 ;
    int z;
    x = 4.0;
    y = 3.0;z=-7;
    printf("The 4 x 4 x 4 is: %7.0f %.0f \n", pow(x, y),pow(4.0,3.0));
    printf("The 3th root of 8 is : %7.4f \n",pow(2*x,1/y));
    printf("The square root of 4 is: %2.0f %.0f \n", sqrt(x),sqrt(4));
    printf("The absulute value of -7 and -7.8 are: %d %.2f\n", abs(z),fabs(n));
    printf(" exp(1)=%f,exp(2)=%f,exp(3)=%f \n", exp(1),exp(2),exp(3));
    printf("exp(pow(2,2))=%f\n",exp(pow(m,2))) ;
    printf("log(100)=%f log10(100)=%f \n",log(100),log10(100));

    return 0;
    }



    /* Use the if statement */
    #include <stdio.h>

    int main(){
    int i;
    printf("Integers that can be divided by both 2 and 3\n");
    printf("(within the range of 0 to 100):\n");
    for (i=0; i<=100; i++)
    if ((i%2 == 0) && (i%3 == 0))
    printf(" %d\n", i);
    return 0;
    }


    /* Use the if statement */
    #include <stdio.h>

    int main(){
    int i;
    printf("Integers that can be divided by both 2 and 3\n");
    printf("(within the range of 0 to 100):\n");
    for (i=0; i<=100; i++)
    if ((i%2 == 0) && (i%3 == 0))
    printf(" %d\n", i);
    return 0;
    }



    /* Use nested if statements */
    #include <stdio.h>

    int main(){
    int i;

    for (i=-5; i<=5; i++){
    if (i > 0){
    if (i%2 == 0)
    printf("%d is an even number.\n", i);
    else
    printf("%d is an odd number.\n", i);
    }else if (i == 0)
    printf("The number is zero.\n");

    else
    printf("Negative number: %d\n", i);
    }
    return 0;
    }


    /* Break an infinite loop */
    #include <stdio.h>

    int main(){
    int c;

    printf("Enter a character:\n(enter x to exit)\n");
    while (1) {
    c = getc(stdin);
    if (c == 'x')
    break;
    }
    printf("Break the infinite while loop. Bye!\n");
    return 0;
    }


    /* Use the continue statement */
    #include <stdio.h>

    int main(){
    int i, sum=0;
    for (i=1; i<8; i++){
    if ((i==3) || (i==5))
    continue;
    sum += i;
    }
    printf("The sum of 1, 2, 4, 6, and 7 is: %d\n", sum);
    return 0;
    }


    #include<stdio.h>
    int main(){
    int i,j,x;
    x=0;
    for ( i=6; i >=2 ; i-=2 ){
    for ( j=i+1; j > 2 ; j-- ){
    if ( (i+j)%3!=0 )
    continue;
    else {
    x+=i+j;
    printf(" i+j=%d \n",i+j);
    }
    }
    }
    printf(" x=%d \n",x);
    return 0;
    }




    #include<stdio.h>
    int main(){
    int n,x,y;
    n=-15;x=0;y=0;
    while( n <= 25){
    while( n < 0 && n%3==0 ){
    printf(" %d \n",n);
    x+=n;
    break;
    }
    while( n > 0 && n%5==0){
    printf(" %d \n",n);
    y+=n;
    break;
    }
    n+=2;
    }
    printf(" x=%d y=%d\n",x,y);
    return 0;
    }


    #include <stdio.h>
    double fonk(int n1, int n2){
    int i;
    double sum=0;
    for (i=n1; i<=n2;i++){
    sum+=i;
    }
    return sum;
    }

    int main(){
    int n1,n2;
    while(1){
    printf("Enter two integer numbers n1 < n2: ");
    scanf("%d%d",&n1,&n2);
    if ( n1 > n2 ){
    printf("n1 should be smaller than n2. TRY AGAIN!... \n");
    continue;
    }
    printf("Toplam=%.0f\n", fonk(n1,n2) );
    }
    return 0;
    }

    /* 12L01.c: Initialize an array */
    #include <stdio.h>
    /*
    ARRAY LIST

    |---|---|---|---|---|---|---|---|---|----|
    | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
    |---|---|---|---|---|---|---|---|---|----|
    */
    int main(){
    int i;
    int list[10];
    for (i=0; i<10; i++){
    list[i] = i + 1;
    printf( "list[%d] is initialized with %d.\n", i, list[i]);
    }
    return 0;
    }



    /* 12L04.c: Print out an array of characters */
    #include <stdio.h>

    int main(){
    char array_ch[7] = {'H', 'e', 'l', 'l', 'o', '!', '\0'};
    int i;

    for (i=0; i<7; i++)
    printf("array_ch[%d] contains: %c\n", i, array_ch[i]);
    /*--- method I ---*/
    printf( "Put all elements together(Method I):\n");
    for (i=0; i<7; i++)
    printf("%c", array_ch[i]);
    /*--- method II ---*/
    printf( "\nPut all elements together(Method II):\n");
    printf( "%s\n", array_ch);

    return 0;
    }



    /* 12L05.c: Stop at the null character */
    #include <stdio.h>

    int main(){
    char array_ch[15] = {'C', ' ',
    'i', 's', ' ',
    'p', 'o', 'w', 'e', 'r',
    'f', 'u', 'l', '!', '\0'};
    int i;
    for (i=0; array_ch[i]; i++)
    printf("%c", array_ch[i]);
    printf("\n");
    return 0;
    }


    /* 12L06.c: Print out a 2-D array */
    #include <stdio.h>
    /*
    COL1 COL2 COL3 COL4 COL5

    |-----|-----|-----|-----|-----|
    ROW1 | 1 | 2 | 3 | 4 | 5 |
    |-----|-----|-----|-----|-----|
    ROW2 | 10 | 20 | 30 | 40 | 50 |
    |-----|-----|-----|-----|-----|
    ROW3 | 100 | 200 | 300 | 400 | 500 |
    |-----|-----|-----|-----|-----|
    */
    int main(){
    int two_dim[3][5] = { {1, 2, 3, 4, 5},
    {10, 20, 30, 40, 50},
    {100, 200, 300, 400, 500} };
    int i, j;
    for (i=0; i<3; i++){
    for (j=0; j<5; j++)
    printf("%6d", two_dim[i][j]);
    printf("\n");
    }
    return 0;
    }



    /* 12L07.c: Initialize unsized arrays */
    #include <stdio.h>

    int main()
    {
    char array_ch[] = {'C', ' ',
    'i', 's', ' ',
    'p', 'o', 'w', 'e', 'r',
    'f', 'u', 'l', '!', '\0'};
    int list_int[][3] = {
    {1, 1, 1},
    { 2, 2, 8},
    {3, 9, 27},
    {4, 16, 64},
    {5, 25, 125},
    {6, 36, 216},
    {7, 49, 343} };


    printf("The size of array_ch[] is %d bytes.\n", sizeof (array_ch));
    printf("The size of list_int[][3] is %d bytes.\n", sizeof (list_int));
    return 0;
    }


    /* 13L01.c: Initialize strings */
    #include <stdio.h>

    int main(){
    char str1[] = {'A', ' ',
    's', 't', 'r', 'i', 'n', 'g', ' ',
    'c', 'o', 'n', 's', 't', 'a', 'n', 't', '\0'};
    char str2[] = "Another string constant";
    int i;

    /* print out str1 */
    for (i=0; str1[i]; i++)
    printf("%c", str1[i]);
    printf("\n");

    /* print out str2 */
    for (i=0; str2[i]; i++)
    printf("%c", str2[i]);
    printf("\n");

    return 0;
    }


    /* 13L02.c: Measure string length */
    #include <stdio.h>
    #include <string.h>

    int main(){
    char str1[] = {'A', ' ',
    's', 't', 'r', 'i', 'n', 'g', ' ',
    'c', 'o', 'n', 's', 't', 'a', 'n', 't', '\0'};
    char str2[] = "Another string constant";

    printf("The length of str1 is: %d bytes\n", strlen(str1));
    printf("The length of str2 is: %d bytes\n", strlen(str2));

    return 0;
    }


    /* 13L03.c: Copy strings */
    #include <stdio.h>
    #include <string.h>

    int main(){
    char str1[] = "Copy a string.";
    char str2[15];
    char str3[15];
    int i;

    /* with strcpy() */
    strcpy(str2, str1);
    /* without strcpy() */
    for (i=0; str1[i]; i++)
    str3[i] = str1[i];
    str3[i] = '\0';
    /* display str2 and str3 */
    printf("The content of str2: %s\n", str2);
    printf("The content of str3: %s\n", str3);
    return 0;
    }



    /* 13L04.c: Use gets() and puts() */
    #include <stdio.h>
    int main(){
    char str[5];
    int i;
    printf("Enter a string ? : ");
    gets( str );
    // scanf("%s",str);
    i = 0;
    while (str[i]){
    if ((str[i] >= 97) && (str[i] <= 122))
    str[i] -= 32; /* convert to upper case */
    i++;
    }
    printf("The entered string is (in uppercase):\n");
    puts( str );
    // printf("%s\n",str);
    return 0;
    }


    #include<stdio.h>
    int fonk(int arr1[],int arr2[]){
    int i,s=0;
    for ( i = 0; i < 6 ; i++)
    if (arr1[i]%2==0)
    arr2[s++]= arr1[i];
    return s;
    }
    int main(){
    int n,i;
    int arr1[]={2,3,4,6,7,12};
    int arr2[10];
    n=fonk(arr1,arr2);
    for (i=0; i < n ; i++)
    printf("%3d ",arr2[i]);
    printf("\n");
    return 0;
    }


    #include<stdio.h>
    int main(){
    int i,j,s=0;
    int arr1[2][3]={{2,3,4},{6,7,12}};
    int arr2[10];

    for ( i = 0; i < 2 ; i++)
    for ( j = 0; j < 3 ; j++)
    if (arr1[i][j]%2==0)
    arr2[s++]=arr1[i][j];

    for (i=0; i < s ; i++)
    printf("%3d ",arr2[i]);
    printf("\n");
    return 0;
    }



    /* 11L01.c: Obtain addresses */
    #include <stdio.h>

    int main()
    {
    char c;
    int x;
    float y;

    printf("c: address=%p, content=%c\n", &c, c);
    printf("x: address=%p, content=%d\n", &x, x);
    printf("y: address=%p, content=%5.2f\n", &y, y);
    c = 'A';
    x = 7;
    y = 123.45;
    printf("c: address=%p, content=%c\n", &c, c);
    printf("x: address=%p, content=%d\n", &x, x);
    printf("y: address=%p, content=%5.2f\n", &y, y);
    return 0;
    }

    /* 11L02.c: Declare and assign values to pointers */
    #include <stdio.h>

    int main()
    {
    char c, *ptr_c;
    int x, *ptr_x;
    float y, *ptr_y;

    c = 'A';
    x = 7;
    y = 123.45;
    printf("c: address=%p, content=%c\n", &c, c);
    printf("x: address=%p, content=%d\n", &x, x);
    printf("y: address=%p, content=%5.2f\n", &y, y);
    ptr_c = &c;
    printf("ptr_c: address=%p, content=%p\n", &ptr_c, ptr_c);
    printf("*ptr_c => %c\n", *ptr_c);
    ptr_x = &x;
    printf("prt_x: address=%p, content=%p\n", &ptr_x, ptr_x);
    printf("*ptr_x => %d\n", *ptr_x);
    ptr_y = &y;
    printf("prt_y: address=%p, content=%p\n", &ptr_y, ptr_y);
    printf("*ptr_y => %5.2f\n", *ptr_y);
    return 0;
    }


    /* 11L03.c: Change values via pointers */
    #include <stdio.h>

    int main()
    {
    char c, *ptr_c;

    c = 'A';
    printf("c: address=%p, content=%c\n", &c, c);
    ptr_c = &c;
    printf("ptr_c: address=%p, content=%p\n", &ptr_c, ptr_c);
    printf("*ptr_c => %c\n", *ptr_c);
    *ptr_c = 'B';
    printf("ptr_c: address=%p, content=%p\n", &ptr_c, ptr_c);
    printf("*ptr_c => %c\n", *ptr_c);
    printf("c: address=%p, content=%c\n", &c, c);
    return 0;
    }


    /* 11L04.c: Pointing to the same thing */
    #include <stdio.h>

    int main()
    {
    int x=1234;
    int *ptr_1, *ptr_2, *ptr_3;


    printf("x: address=%p, content=%d\n", &x, x);
    ptr_1 = &x;
    printf("ptr_1: address=%p, content=%p\n", &ptr_1, ptr_1);
    printf("*ptr_1 => %d\n", *ptr_1);
    ptr_2 = &x;
    printf("ptr_2: address=%p, content=%p\n", &ptr_2, ptr_2);
    printf("*ptr_2 => %d\n", *ptr_2);

    ptr_3 = &x;
    printf("ptr_3: address=%p, content=%p\n", &ptr_3, ptr_3);
    printf("*ptr_3 => %d\n", *ptr_3);

    return 0;
    }

  10. #10
    ASTSUBAY
    Üyelik tarihi
    Nov 2005
    Mesajlar
    768
    Forum Katkısı:
    0

    Standart C örnekleri

    eyvallah kardeş sıkı &#231;alışma emeğine sağlık yalnız
    altta yazılı olan &#246;rnekleri d&#252;zeltirmisin

    ptr_3 = &x;
    printf("ptr_3: address=%p, content=%p\n", &ptr_3, ptr_3);
    printf("*ptr_3 => %d\n", *ptr_3);

    return 0;
    }

Toplam 3 Sayfadan 1. Sayfa 123 SonuncuSonuncu

Konu Bilgisi

Users Browsing this Thread

Şu anda 1 üyemiz bu konuya göz atıyor. (0 kayıtlı üye ve 1 misafir.)

Bu Konuyu Paylaşın !

Bu Konuyu Paylaşın !

Yetkileriniz

  • Konu Acma Yetkiniz Yok
  • Cevap Yazma Yetkiniz Yok
  • Eklenti Yükleme Yetkiniz Yok
  • Mesajınızı Değiştirme Yetkiniz Yok
  •  
Garantili SEO - Moradam