-->

تمارين محلوله في لغة السي exercice avec corrigé langage c

تمارين محلوله في لغة السي  exercice avec corrigé langage c

    تمارين محلوله في لغة السي  exercice avec corrigé langage c    



    تمارين محلوله في لغة السي
    تمارين محلوله في لغة السي

    تمرین: 01أكتب برنامج یقوم بجمع عددین صحیحین .الحــــــــــل:
    #include <stdio.h>

    void main ()
    { int a,b ,s;
    printf ("donnnez un entier =");
    scanf("%d",&a);
    printf("donnez un autre entier=");
    scanf("%d",&b);
    s=a+b;
    printf("le rsultat=%d",s);
    }
    التمرین: 02أكتب برنامج یقوم بحساب ضعف عدد صحیح.
    الحـــــــــــــــــل:
    #include <stdio.h>
    void main ()
    { int a,d ;
    printf (« donnnez un entier = ») ;
    scanf(« %d »,&a) ;
    d=a*2 ;
    printf(« le rsultat=%d »,d) ;}



    التمرین : 03
    أكتب برنامج یقوم بإدخال إسم طالب و العلامات المتحصل علیھا ثم یحسب المعدل
    الحــــــــــــل:

    #include <stdio.h>
    void main ()
    { float not1,not2,not3,m;
    char n[15],p[15] ;
    printf (« le nom d’etudiant= ») ;
    scanf(“%s”,&n);
    printf(“\n”);
    printf (« le prenom d’etudiant= ») ;
    scanf(« %s »,&p) ;
    printf(« \n ») ;
    printf (« les notes d’etudiant ») ;
    printf(“\n”);
    printf(“module1=”);
    scanf(“%f”,¬1);
    printf(“\n”);
    printf(“module2=”);
    scanf(“%f”,¬2);
    printf(“\n”);
    printf(“module3=”);
    scanf(“%f”,¬3);
    printf(“\n”);
    m=(not1+not2+not3)/3;
    //affichage
    printf(“nom =”);
    printf(“%s”,&n);
    printf(“\n”);
    printf(“prenom =”);
    printf(“%s “,&p);
    printf(« \n ») ;
    printf(« moyenne %.2f »,m) ; //%.2f pour afficher 2 chiffre apre la
    virgule
    }
    التمرین :04
    أكتب برنامج یقوم بحل معادلة من الدرجة الثانیة
    الحـــــــــــــل:
    #include <stdio.h>
    #include <math.h>
    void main ()
    { float a,b,c,d,x1,x2,x;
    printf(« entrez un nombre reel= ») ;
    scanf(« %f »,&a) ;
    printf(« entrez un nombre reel= ») ;
    scanf(« %f »,&b) ;
    printf(« entrez un nombre reel= ») ;
    scanf(“%f”,&c);
    d=(b*b)-(4*a*c);
    if (d==0)
    { x=(-b)/(a+a);
    printf(“la racine x1=x2= %.2f”,x); }
    else
    if (d>0)
    { x1=(-b+sqrt(d))/(2*a);
    x2=(-b-sqrt(d))/(2*a) ;;
    printf(« la racine x1= %.2f »,x1) ;
    printf(« \n ») ;
    printf(« la racine x2= %.2f »,x2) ; }
    else
    { printf(« pas de solution ») ;}
    }




    التمرین :05أكتب برنامج یقوم بحساب المجموع التالي:s=1+2+3……..+n
    الحـــــــــل:
    #include <stdio.h>
    #include <conio.h>

    void main ()
    7
    { int n,i,s=0 ;
    printf(« entrez un nombre entier « ) ;
    scanf(“%d”,&n);
    if (n<1)
    {printf(« entrez un nombre >=1 ») ;
    }
    else
    {
    for (i=1;i<=n;++i)
    { s=s+i;
    }printf(« la somme= %d »,s) ;
    } }
    التمرین : 06
    أكتب برنامج یقوم بإدخال رقم من 1إلى 7ثم یقوم بإعطاء الیوم الموافق
    الحــــــــل:
    #include <stdio.h>
    void main ()
    { int j ;
    printf(« donnez un numéro <*1.samedi*2.dimanche*3.lundi*….> ») ;
    scanf(“%d”,&j);
    switch (j)
    { case 1: printf(“samedi”); break;
    case 2: printf(“dimanche”);break;
    case 3: printf(“lundi”); break;
    case 4: printf(“mardi”); break;
    case 5: printf(“mercredi”);break;
    case 6: printf(“jeudi”); break;
    case 7 : printf(« vendredi ») ; break ;
    default :printf(« existe pas ») ;
    }}
    .2الــــــــــــدوال

    التمرین :01
    أكتب برنامج یقوم بإدخال عددین صحیحین ثم یعطي العدد الأكبر بإستعمال
    الدوال.
    الحـــــــــل:
    #include<stdio.h>
    int plusg (int,int) ;
    void main()
    { int a,b,r ;
    printf(« entrez un entier= ») ;
    scanf(« %d »,&a) ;
    printf(« entrez un entier= ») ;
    scanf(« %d »,&b) ;
    r=plusg(a,b) ;
    printf(« le plus grand nombre entre %d et %d = %d »,a,b,r) ;
    }
    int plusg (int a,int b)
    { if (a>b)
    return a;
    else return b;}
    التمرین :02
    أكتب برنامج یقوم بإدخال عددین صحیحین ثم یعطي العددالأصغر بإستعمال
    الدوال.
    الحـــــــــل:
    #include<stdio.h>
    int plusp (int,int) ;
    void main()
    { int a,b,r ;
    printf(« entrez un entier= ») ;
    scanf(« %d »,&a) ;
    printf(« entrez un entier= ») ;
    9
    scanf(« %d »,&b) ;
    r=plusp(a,b) ;
    printf(« le plus petite nombre entre %d et %d = %d »,a,b,r) ;
    }
    int plusp (int a,int b)
    { if (a>b)
    return b;
    else return a;}
    التمرین : 03
    لیكن لدینا :
    p1=1 si n=1
    p2=1 si n=2
    pn=pn-1+pn-2
    أكتب دالة تقوم بحساب كثیر الحدود
    الحـــــــــل:
    #include <stdio.h>
    poly (int );
    void main()
    { int n,r ;
    printf(« entrz un entier = ») ;
    scanf(“%d”,&n);
    r=poly(n);
    printf(« la valeur de polynome=%d »,r) ;
    }
    int poly(int n)
    {
    if ((n==1) || (n==2))
    return 1;
    else
    return(poly(n-1)+poly(n-2));
    }
    10
    التمرین :04
    لیكن لدینا :
    p0=2 si n=0
    p1=3 si n=1
    p2=4 si n=2
    pn=2(pn-1+5)+pn-2
    أكتب دالة تقوم بحساب كثیر الحدود السابق
    الحـــــــــــــل:
    #include <stdio.h>
    poly (int );
    void main()
    { int n,r;
    printf("entrz un entier =");
    scanf("%d",&n);
    r=poly(n);
    printf("la valeur de polynome=%d",r);
    }
    int poly(int n)
    {
    if (n==0)
    return 2;
    else
    if (n==1) return 3;
    else
    if (n==2) return 4;
    else
    return 2*(poly(n-1)+5)+poly(n-2);
    }
    التمرین :05
    أكتب برنامج یقوم بإدخال إسم طالب والنقاط المحصل علیھا ثم یقوم بحساب المعدل وأكبر
    وأصغر نقطة متحصل علیھا بإستعمال الدوال.
    الحــــــــــــل:





    #include <stdio.h>
    #include <conio.h>
    float moy (float,float,float);
    float plusp (float,float,float);
    float plusg (float,float,float);
    void main()
    { float n1,n2,n3,m,np,ng;
    char nom[10];
    printf("entrez le nom d'etudaint=");
    scanf("%s",&nom);
    printf("entrez les notes =");
    scanf("%f%f%f",&n1,&n2,&n3);
    printf("\n");
    clrscr(); //effacer l'ecran
    printf(" l'etudiant =%s",nom);
    printf("\n");
    m=moy ( n1,n2, n3);
    printf("la moyenne = %.2f",m);
    printf("\n");
    np=plusp (n1,n2,n3);
    printf("la petite note = %.2f",np);
    printf("\n");
    ng=plusg (n1,n2,n3);
    printf("la grand note = %.2f",ng);
    }
    //**************************************
    float moy (float n1,float n2,float n3)
    {
    return (n1+n2+n3)/3;}
    //***************************************************
    float plusp (float n1,float n2,float n3)
    { if (n1<n2)
    { if (n1<n3)
    return n1;
    else
    12
    return n3; }
    else
    { if (n2<n3)
    return n2;
    else
    return n3; } }
    //***************************************************
    float plusg (float n1,float n2,float n3)
    { if (n1<n2)
    { if (n2<n3)
    return n3;
    else
    return n2; }
    else
    { if (n1<n3)
    return n3;
    else
    return n1; } }

    .3الجـــــداول

    التمرین:01
    أكتب برنامج یقوم بحساب معدل عناصر جدول.
    الحــــــل:
    #include <stdio.h>
    void main ()
    { float t[10],m,som=0;
    int I;
    13
    printf(« entrz les elements de tableau \n ») ;
    for (i=0;i<5;++i)
    {scanf(“%f”,&t[i]);
    Som =som+t[i]; }
    m=som/5;
    printf(« la moyenne =%.2f »,m) ; }
    التمرین :02
    أكتب برنامج یقوم بإیجاد أكبر عنصر في جدول.
    الحــــــل:
    #include <stdio.h>
    void main ()
    { float t[5],m;
    int i;
    printf("entrez les elements de tableau=");
    printf("\n");
    for (i=0;i<5;i++)
    {scanf("%f",&t[i]); }
    m=t[0];
    for (i=0;i<5;i++)
    {if (m < t[i])
    m=t[i]; }
    printf("le max du tableau= %.2f",m); }
    التمرین :03
    أكتب برنامج یقوم بترتیب جدول.
    الحـــــل:
    #include <stdio.h>
    void main ()
    { int t[5],x;
    14
    int i,j;
    printf("entrez les elements de tableau=");
    printf("\n");
    for (i=0;i<5;i++)
    {scanf("%d",&t[i]); }
    for (i=0;i<4;i++)
    { j=i+1;
    while (j<= 5)
    { if (t[j] < t[i])
    { x=t[j];
    t[j]=t[i];
    t[i]=x; }
    j=j+1;} }
    printf("le tableau treir\n");
    for (i=0;i<5;i++)
    printf("%d\n",t[i]);}
    .4تمریر الجداول كمتغیرات

    التمرین:01
    أكتب برنامج یقوم بترتیب جدول ودلك بإستعمال الدوال
    الحــــــــــل:
    #include <stdio.h>
    void tri_croi(int t[]);
    void main()
    { int i,n,t[10];
    printf("la taille du tableau=");
    scanf("%d",&n);
    for (i=0;i<n;++i)
    { printf("\n donnez t[%d]:",i);
    scanf("%d",&t[i]);
    }
    15
    tri_croi(t); // appel de fonction
    }
    void tri_croi(int t[])
    {int i,j,x,n;
    for (i=0;i<=n;++i)
    for (j=i+1;j<n+1;++j)
    if (t[i]> t[j] )
    { x=t[j];
    t[j]=t[i];
    t[i]=x; }
    for (i=0;i<=n;++i)
    printf("\nelemet t[%d]:%d",i,t[i])
    .5سلسلة الحروف

    التمرین:01
    أكتب برنامج یقوم بإدخال سلسلتین حرفیتین ثم یقوم بدمجھما .
    الحـــــل:
    #include <stdio.h>
    #include <string.h>
    void main ()
    {
    char c1[20],c2[20];
    printf("entrez la chaine1:");
    scanf("%s",&c1);
    printf("\n");
    printf("entrez la chaine2:");
    scanf("%s",&c2);
    strcat(c1,c2); // la fonction de concaténation
    printf("\n resultat de concaténation:%s ",c1) ;
    }




    التمرین:02
    أكتب برنامج یقوم بحساب عدد حروف سلسلة .
    الحـــــل:


    #include <stdio.h>
    #include <string.h>
    void main ()
    {
    char c1[20];
    int t;
    printf("entrez la chaine:");
    scanf("%s",&c1);
    t=strlen(c1); // la fonction qui calcule la taille
    printf("\n la taille de la chaine :%d ",t) ;
    }
    Exercice n°3 :

    التمرین :03
    أكتب برنامج یقوم بتحویل حجم السسلسلة من الصغیر إلى الكبیر
    الحــــل:
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    void main ()
    {
    char c1[20];
    int t,i;
    printf("entrez la chaine:");
    scanf("%s",&c1);
    t=strlen(c1); // la fonction qui calcule la taille
    17
    for (i=0;i<t;i++)
    c1[i]=toupper(c1[i]); // la fonction qui covert de minu ver maju
    printf("\n la chaine majuscule :%s ",c1) ;
    }
    التمرین:04
    أكتب برنامج یقوم بتحویل حجم السسلسلة من الكبیرإلى الصغیر
    الحــــل:
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    void main ()
    {
    char c1[20];
    int t,i;
    printf("entrez la chaine:");
    scanf("%s",&c1);
    t=strlen(c1); // la fonction qui calcule la taille
    for (i=0;i<t;i++)
    c1[i]=tolower(c1[i]); // la fonction qui covert de maju ver minu
    printf("\n la chaine majuscule :%s ",c1) ;
    }
    التمرین :05
    أكتب برنامج یقوم بحساب عدد حروف جملة
    الحـــل:
    18
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    void main ()
    {
    char phrase[80];
    int i,nb,t;
    printf(" entrez une phrase :\n");
    gets(phrase);
    nb=0;
    t=strlen(phrase);
    for (i=0;i<t;++i)
    {if((phrase[i]==' ')|| (phrase[i]=='.') )
    nb=nb+1; }
    printf("le nombre de mot=%d",nb);}
    .6البـــــنى

    التمرین :01
    أكتب برنامج یقوم بإدخال متغیر مركب من عدة أنواع.
    الحـــــل:
    #include <stdio.h>
    typedef struct compte { int numc;char nom[20];} ;
    void main ()
    {
    compte c ;
    printf(" le numero de compte: ");
    scanf("%d",&c.numc);
    printf("\n");
    printf(" le nom du client: ");
    scanf("%s",&c.nom);
    printf(" le client:\n");
    19
    printf("num :%d",c.numc);
    printf("\n");
    printf("nom :%s",c.nom);
    .7المؤشرات

    التمرین:01
    أكتب برنامج یقوم بعرض قیمة المتغیر ومكانھ في الداكرة
    الحــــل:
    #include <stdio.h>
    void main ()
    {
    int a=5,*b; // apre l'execution a=5 et *b=5
    b=&a;
    printf("a=%d et *b=%d",a,*b);}
    التمرین:01
    أكتب برنامج یقوم بعرض قیمة المتغیر ومكانھ في الداكرة
    الحــــل:
    #include <stdio.h>
    void main ()
    {
    int u=5,v,*x,*y; // apre l'execution a=5 et *b=5
    x=&u;
    y=&v ;
    v=*x+2;
    printf("\n u=%d",u);
    printf("\n *x=%d",*x);
    printf("\n v=%d",v);
    printf("\n *y=%d",*y); }



































    ta9afatimes
    @مرسلة بواسطة
    كاتب ومحرر اخبار اعمل في موقع ثقافة تايمز .

    إرسال تعليق