Commit 5c120219 authored by Anthony Bocquet's avatar Anthony Bocquet

initial commit

parent 3a2200f7
Pipeline #30289 canceled with stages
{
"files.associations": {
"tp3.h": "c"
}
}
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
typedef struct Element Element;
struct Element{
int nombre;
Element *suivant;
};
typedef struct Liste Liste;
struct Liste{
Element *premier;
};
int main(int argc, char const *argv[])
{
return 0;
}
diff(Liste* a, Liste* b, Liste* c){
if(a->premier->nombre == b->premier->nombre){
Liste* succa = malloc(sizeof(*succa));
succa->premier = a->premier->suivant;
Liste* succb = malloc(sizeof(*succb));
succb->premier = b->premier->suivant;
diff(succa, succb, c);
}
if(a->premier == NULL){
}
}
\ No newline at end of file
File added
#include <stdio.h>
#include <stdlib.h>
struct Structmonome{
int coef;
int deg;
struct Structmonome* suivant;
};
typedef struct Structmonome* Polynome;
Polynome polynomeconstructeur(int c, int d, Polynome P);
int degre(Polynome p);
void afficherPolynome(Polynome p);
int main(int argc, char const *argv[])
{
return 0;
}
Polynome polynomeconstructeur(int c, int d, Polynome p){
struct Structmonome *Monome = malloc(sizeof(struct Structmonome));
if(Monome == NULL){
exit(EXIT_FAILURE);
}
Monome->coef = c;
Monome->deg = d;
Monome->suivant = p;
p = Monome;
return p;
};
int degre(Polynome p){
int deg = -1;
Polynome pm = p;
while(pm != NULL){
if(pm->deg > deg) deg = pm->deg;
pm = pm->suivant;
}
return deg;
}
void afficherPolynome(Polynome p){
Polynome pm = p;
while(pm != NULL){
if(pm->coef != 0){
if(pm->deg == 0){
printf("%d", pm->coef);
}
else if(pm->deg == 1) {
printf("%d x", pm->coef);
}
else{
printf("%d x^%d", pm->coef, pm->deg);
}
}
if(pm->suivant->coef > 0) printf("+");
pm = pm->suivant;
}
}
\ No newline at end of file
File added
#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 20
typedef struct pile {
int tete;
int pile[MAX_SIZE];
} pile_t;
pile_t* creer_pile();
int pile_vide(pile_t* pile);
void empiler(pile_t* pile, int val);
int depiler(pile_t* pile);
int main(int argc, char const *argv[])
{
pile_t* pile = creer_pile();
printf("%d\n", pile->tete);
printf("%d\n", pile_vide(pile));
empiler(pile, 7);
empiler(pile, 2);
printf("%d\n", depiler(pile));
printf("%d\n", pile_vide(pile));
return 0;
}
/* -------------------------------------------- */
pile_t* creer_pile(){
pile_t* pile = malloc(sizeof(pile_t));
pile->tete = 0;
return pile;
};
int pile_vide(pile_t* pile){
if(pile->tete == 0) return 1;
return 0;
};
void empiler(pile_t* pile, int val){
pile->pile[pile->tete] = val;
pile->tete++;
};
int depiler(pile_t* pile){
pile->tete--;
int temp = pile->pile[pile->tete];
pile->pile[pile->tete] = 0;
return temp;
};
\ No newline at end of file
File added
#include <stdio.h>
#include <stdlib.h>
#define MAX_F 10
typedef struct file{
int tete;
int queue;
int tab[MAX_F];
} file_t;
file_t* creer_file();
int file_vide(file_t* file);
void enfiler(file_t* file, int val);
int main(int argc, char const *argv[])
{
file_t* file = creer_file();
printf("%d, %d\n", file->queue, file->tete);
enfiler(file, 7);
printf("%d, %d\n", file->queue, file->tete);
printf("%d, %d\n", file->tab[file->queue], file->tab[file->tete]);
return 0;
}
file_t* creer_file(){
file_t* file = malloc(sizeof(file_t));
file->tete = 0;
file->queue = 0;
};
int file_vide(file_t* file){
if(file->tete == file->queue) return 1;
return 0;
};
void enfiler(file_t* file, int val){
file->tab[file->queue] = val;
if(file->queue == MAX_F - 1){
file->queue = 0;
}else{
file->queue++;
}
}
\ No newline at end of file
#include <stdio.h>
// Programme 1
void main (){
int A=20 , B=5;
int C=!--A /++! B; //error: expression is not assignable
printf ("A=%d B=%d c=%d \n", A,B,C);
}
// Programme 2
// int main (){
// int A=20 , B=5, C= -10, D=2;
// printf ("%d \n", A&&B ||!0&& C ++&&! D++); // 1
// printf ("c=%d d=%d \n", C, D); // c = -10 | d = 2
// }
// Programme 3
// int main (){
// int p[4]={1 , -2 ,3 ,4};
// int *q=p;
// printf("%d",*q);
// printf ("c=%d\n", *++q**q ++); // c = 4
// printf ("c=%d \n" ,*q); // c = 3
// }
// Programme 4
// int main (){
// int p [4]={1 , -2 ,3 ,4};
// int *q=p;
// int d=*q&*q ++|* q++;
// printf ("d=%d\n", d); // d = -1
// printf ("q=%d \n" ,*q); // q = 3
// }
// Programme 5
// int main (){
// int a=-8,b =3;
// int c= ++a&&--b ? b-- :a ++;
// printf ("a=%d b=%d c=%d\n",a,b,c); // a = -7 | b = 1 | c = 2
// }
// Programme 6
// int main (){
// int a=-8,b =3;
// a > >=2^b; // error: expected expression
// printf ("a=%d\n",a); // a=-3
// }
#include <stdio.h>
int main(int argc, char const *argv[])
{
int a,b = 0;
printf("Entrez le 1er nombre : ");
scanf("%i", &a);
printf("\nEntrez le 2eme nombre : ");
scanf("%i", &b);
printf("\n%i + %i = %i\n", a, b, a+b);
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
int a, b, temp = 0;
printf("a = ?");
scanf("%d", &a);
printf("\nb = ?");
scanf("%d", &b);
// inversion
temp = a;
a = b;
b = temp;
printf("\na = %d , b = %d\n", a, b);
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
float x, y = 0;
printf("Entrez un nombre : ");
scanf("%f", &y);
printf("\nEntrez un pourcentage : ");
scanf("%f", &x);
printf("\n%f %% de %f = %f\n", x, y, (x*y)/100);
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
float f, c;
printf("Entrez une température en Fahrenheit : ");
scanf("%f", &f);
c = (5/9)*(f - 32);
printf("\n %f Fahrenheit = %f Celsius\n", f, (f-32)*5/9);
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
int a = 0;
printf("Entrez un entier : ");
scanf("%d", &a);
printf("\n%d en hexadecimal vaut : %x\n", a, a);
printf("\n%d en octal vaut : %o\n", a, a);
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
int i = 0;
printf("Entrez un entier : ");
scanf("%d", &i);
if(i == 0){
printf("\nLe nombre entré vaut 0.\n");
} else{
if(i % 2 == 0){
printf("\nLe nombre entré est pair.\n");
} else{
printf("\nLe nombre entré est impair.\n");
}
}
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
char c = '5';
printf("%c", c);
c = 53;
printf("\n%c\n", c);
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
char a;
printf("Entrez un chiffre ou un caractère : ");
scanf("%c", &a);
if(a > 47 && a < 58){
printf("Le caractère entré est un chiffre\n");
}
if(a > 64 && a < 91){
printf("Le caractère entré est une lettre majuscule\n");
}
if(a > 96 && a < 123){
printf("Le caractère entré est une lettre minuscule\n");
}
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
int a = 0;
printf("Entrez un nombre : ");
while(a != -1){
scanf("%d", &a);
if(a != -1) printf("Vous avez entré %d ! Faites -1 pour quitter.\n", a);
}
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
char c;
int quit = 0;
int table;
while(quit != 1){
printf("Quelle table de multiplication voulez-vous, tapez 0(zéro) pour sortir ?");
scanf("%c", &c);
if(c > 48 && c < 58){
table = ((int)c) - 48;
for(int i = 0; i < 11; i++){
printf("%d x %d = %d\n", table, i, table*i);
}
} else if(c == 48) {
quit = 1;
printf("Fermeture du programme !\n");
} else if(c < 48 | c > 57){
printf("Ce n'est pas dans les possibilités du programme, recommencez !\n");
}
}
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
char c;
printf("Entrez 1 2 ou 3 : ");
switch(c = getchar()){
case 49 : printf("1\n");
break;
case 50 : printf("2\n");
break;
case 51 : printf("3\n");
break;
default : printf("autre caractère\n");
}
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
int tab[10];
for(int i = 0; i < 10; i++){
tab[i] = 0;
}
for(int i = 0; i < 10; i++){
printf("%d\n", tab[i]);
}
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
int tab[5] = {4,3,2,1,0};
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
int tab[3][4] = {{12,13,14,15},
{16,17,18,19},
{20,21,22,23}};
for(int j = 0; j < 3; j++){
for(int i = 0; i < 4; i++){
printf("%d", tab[j][i]);
}
printf("\n");
}
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
return 0;
}
#include <stdio.h>
void permute(int*, int*);
int main(int argc, char const *argv[])
{
int a, b;
printf("Entrez a : ");
scanf("%d", &a);
printf("Entrez b : ");
scanf("%d", &b);
permute(&a, &b);
printf("a = %d et b = %d \n", a, b);
return 0;
}
// On utilise des pointeurs pour faire un passage par adresse et ainsi avoir accès aux variables et non à une copie
void permute(int *a, int *b){
int temp = *a;
*a = *b;
*b = temp;
}
\ No newline at end of file
#include <stdio.h>
int main(int argc, char const *argv[])
{
int i;
int *j;
i = 5;
j = &i;
printf("i = %d\nj = %p\n*j = %d\n", i, j, *j);
return 0;
}
#include <stdio.h>
int main(int argc, char const *argv[])
{
int i;
int *j;
i = 5;
j = &i;
*j = *j + 1;
printf("i = %d\n", *j);
i *= 5;
printf("i = %d\n", *j);
j++;
printf("*j = %d\n", *j);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
int *tab[3];
int k = 12;
for(int i = 0; i < 3; i++){
tab[i] = malloc(sizeof(int)*4);
for(int j = 0; j < 4; j++){
tab[i][j] = k;
k++;
}
}
for(int j = 0; j < 3; j++){
for(int i = 0; i < 4; i++){
printf("%d", tab[j][i]);
}
printf("\n");
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
int **tab;