9 Novembre

This commit is contained in:
Adrian POURCHOT 2022-11-09 17:12:39 +01:00
parent a9e98afad2
commit b2789803aa
4 changed files with 148 additions and 0 deletions

View File

@ -0,0 +1,66 @@
#include <stdio.h>
#include <stdlib.h>
void triangle(int h) {
int i;
int j;
int e;
for (i=0;i<=h;i++){
for (j=h-i;j>0;j--){
} for (e=0;e<i;e++){
printf("*");
} printf("\n");
}
}
void carre(int h){
int i;
int j;
for (i=1;i<=h;i++){
for (j=1;j<=h;j++){
if (j==1||j==h){
printf("* ");
} else{
if (i==1||i==h){
printf("* ");
}else{
printf(" ");
}
}
}printf("\n");
}
}
char menu() {
char n;
printf("_______________\nt) Triangle\nc) Carre\nq) Quitter\nVotre choix ? ");
scanf(" %c",&n);
return n;
}
int main() {
int z=0;
int h;
char c;
while(z==0){
c=menu();
if (c=='t'){
printf("Hauteur ? ");
scanf("%d",&h);
triangle(h);
} else {
if (c=='c'){
printf("Hauteur ? ");
scanf("%d",&h);
carre(h);
} else{
if(c=='q'){
printf("Au revoir...\n\n");
break;
}
}
}
}
return 0;
}

View File

@ -0,0 +1,18 @@
#include <stdio.h>
#include <stdlib.h>
void echange(int* a , int* b){
int c;
c=*a;
*a=*b;
*b=c;
}
int main(void) {
int x=14;
int y=29;
printf("avant : %d %d\n", x, y);
echange(&x,&y);
printf("apres : %d %d\n", x, y);
return 0;
}

View File

@ -0,0 +1,49 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void echange(int* a , int* b){
int c;
c=*a;
*a=*b;
*b=c;
}
int afficheTab (int tab[]){
int i;
printf("+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+\n");
for (i=0;i<10;i++){
printf("| %3d ",tab[i]);
} printf("|\n+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+\n");
}
int remplissageAleatoire (int tab[]){
int i;
srand(time(NULL));
for (i=0;i<10;i++){
tab[i]=((rand()%101)-50);
}
}
int inverseTab (int tab[]){
int i;
int j;
int k;
printf("Voici le tableaux inverse:\n+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+\n");
i=9;
for(j=0;j<5;j++){
echange(&tab[i],&tab[j]);
i--;
}
for (i=0;i<10;i++){
printf("| %3d ",tab[i]);
} printf("|\n+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+\n");
}
int main() {
int tab[10];
remplissageAleatoire(tab);
afficheTab(tab);
inverseTab(tab);
return 0;
}

View File

@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
void zero(double* a) { //bien penser à utiliser des pointeurs pour modifier les valeurs en dehors de la fonction.
*a = 0.0;
}
int main(void) {
double x=37.5;
printf("avant : %f\n", x);
zero(&x);
printf("apres : %f\n", x);
return 0;
}