Skip to content
Snippets Groups Projects
Commit 389c2b90 authored by mathias.catala's avatar mathias.catala
Browse files

"first commit"

parent 97ae5251
No related branches found
No related tags found
No related merge requests found
File added
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
double Function_value (double x){
//double function = 3*pow(x,3)+ pow(x,2) - 27;
double function = sin(x);
return function;
}
float sign(double x){
if(x > 0){
return 1;
}else if (x<=0){
return -1;
}
}
int study_function(double epsilon,double low, double high){
double counter=0;
while (low<high){
low +=epsilon;
double now = sign(Function_value(low));
double previous = sign(Function_value(low-epsilon));
if( previous !=now ) counter++;
}
printf("nombre de changement: %f\n", counter);
return counter;
}
int main(){
double espilon = 0.1;
double low = -3.5;
double high = 3.5;
study_function(espilon,low,high);
return 0;
}
File added
File added
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 10
int main(){
srand(time(NULL));
double tab[SIZE];
//génère une liste de 10 élements aléatoire
for (int i=0; i < SIZE; ++i){
tab[i] = rand()/(double)RAND_MAX;
//printf("%d\n",tab[i]);
}
// génère une liste de 9 éléments aléatoire
for (int i = 0 ; i< SIZE -1 ; ++i){
tab[i] = rand() / (double)RAND_MAX;
//printf("%d\n",tab[i]);
}
//tri la liste avec la valeur la plus petite
for (int i = 0; i < SIZE - 1; ++i) {
double min = tab[i];
int ind_min = i;
for (int j = i + 1; j < SIZE; ++j) {
if (min > tab[j]) {
ind_min = j;
min = tab[j];
}
}
double tmp = tab[i];
tab[i] = tab[ind_min];
tab[ind_min] = tmp;
printf("Test :%f\n",tab[ind_min]);
}
for (int i = 0; i < SIZE; ++i) {
printf("%f ", tab[i]);
}
printf("\n");
for (int i = 0; i < SIZE - 1; ++i) {
if (tab[i] > tab[i + 1]) {
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}
{
"folders": [
{
"path": ".."
}
],
"settings": {
"files.associations": {
"COURS.C": "cpp"
}
}
}
\ No newline at end of file
File added
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <math.h>
#define N 10
void eratosthene( int n, bool tab[]){
int i,j;
for(i = 2; i <= N; i++)
{
if(tab[i] ==true)
{
for(j = pow(i, 2); j <= N; j +=i)
{
tab[j] = false;
}
}
}
}
int main(){
bool tab[N];
int result;
for (int i = 0; i <= N ; i++) {
tab[i]=true;
}
eratosthene(N,tab);
for (int i =2 ; i <= N-1 ; i++) {
if(tab[i]==1){
printf("%d ",i);
}
}
return 0;
}
int main()
{
int num[N], i, j;
int limit = sqrt(N);
for(i = 0; i < N; i++)
num[i] = i + 1;
for(i = 1; i <= limit; i++)
{
if(num[i] != 0)
{
for(j = pow(num[i], 2); j <= N; j = j + num[i])
{
num[j - 1] = 0;
}
}
}
printf("Sieve of Eratosthenes Method\n");
printf("To find Prime numbers from 2 to %d\n\n", N);
for(i = 1; i < N; i++)
{
if(num[i] != 0)
printf("%d\t", num[i]);
}
printf("\n");
return 0;
}
File added
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
void sort (char str[]){
char temp;
for(int i = 0; i <=strlen(str)-1 ; i++){
for ( int j = i+1; j < strlen(str); j++){
if(str[i]>str[j]){
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
}
}
bool isanagram(char str1[], char str2[]){
sort(str1);
sort(str2);
printf("test: %s \n",str1);
printf("test: %s \n",str2);
if (!strcmp(str1,str2)){
printf("YES");
return true;
}else return false;
}
void revert (char str1[]){
int temp;
int max_right = strlen(str1)-2;
for(int i = 0; i <max_right; i++){
temp = str1[max_right];
str1[i] = str1[max_right];
str1[max_right] = temp;
max_right--;
}
printf("%s",str1);
char str2[60];
strcpy(str2,str1);
//printf("%s",str2);
}
bool ispalindrome(char str1[], char str2[]){
}
int main(int argc, char **argv){
char str1[] = "kayak";
char str2[]= "mdr" ;
//char *str1 = argv[1];
//char *str2 = argv[2];
//printf("%s",argv[0]);
//if (isanagram(str1,str2)) printf("Les deux chaines sont des anagrames");
//else printf("Les deux chaines ne sont pas des anagrames");
revert(str2);
// sort(name);
// printf("%s",name);
// printf("char length : %d ",strlen(name));
return 0 ;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
void revert (char str1[], char str2[]){
}
bool ispalindrome(char str1[], char str2[]){
}
int main(ar){
return 0 ;
}
\ No newline at end of file
myTP/exo1 0 → 100644
File added
#include <stdio.h>
void recurse(int n){
printf("%d", n%2);
if(n/2!=0){
recurse(n/2);
}else {
printf("\n");
}
}
int fibonacci( int i){
if(i>1){
return printf("fibo: %u \n",fibonacci(i-1)+fibonacci(i-2));
}
return i;
}
int main(){
//recurse(13);
fibonacci(6);
return 0;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment