Différences entre versions de « C algo td4 »
Aller à la navigation
Aller à la recherche
Ligne 45 : | Ligne 45 : | ||
} | } | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | <source lang="c"> | ||
+ | #include <stdio.h> | ||
+ | #include <string.h> | ||
+ | |||
+ | int main(int argc, const char * argv[]) | ||
+ | { | ||
+ | int degre,i; | ||
+ | char poly[50]; | ||
+ | |||
+ | printf("Quel degre : "); | ||
+ | scanf("%d", °re); | ||
+ | |||
+ | int coef[degre]; | ||
+ | |||
+ | printf("\n"); | ||
+ | |||
+ | for (i=0; i<degre; i++) { | ||
+ | printf("Rentrez la valeur du coefficient %d : ",i+1); | ||
+ | scanf("%d", &coef[i]); | ||
+ | sprintf(poly, "X^%d", coef[i]); | ||
+ | if (i < degre-1) { | ||
+ | strcat(poly, "X"); | ||
+ | strcat(poly, " + "); | ||
+ | }else if (i != degre){ | ||
+ | sprintf(poly, "X^%d", degre-i); | ||
+ | strcat(poly, " + "); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | printf("%s", poly); | ||
return 0; | return 0; | ||
} | } | ||
</source> | </source> |
Version du 12 mars 2014 à 12:18
#include <stdio.h>
int main()
{
int ligne,colonne,i,j;
printf("Combien de lignes : "); //Le nombe de colonnes pour la matrice voulue
scanf("%d", &ligne);
printf("Combien de colonnes : "); //Le nombre de colonnes pour la matrice voulue
scanf("%d", &colonne);
int sqc=ligne+colonne-1, sequence[sqc];
int mat[ligne][colonne];
printf("\n");
for (i=0; i<sqc; i++) { //On connait le nombre de séquence c'est "sqc"
printf("Rentrez la valeur de l'index %d : ",i+1);
scanf("%d", &sequence[i]); //On rentre les valeurs de la matrice
}
for (i=0; i<ligne; i++) {
for (j=0; j<colonne; j++) {
if (i==0) {
mat[i][j]=sequence[j];
}else{
if(j == 0){
mat[i][j]=sequence[colonne+i-1];
}else{
mat[i][j]=mat[i-1][j-1];
}
}
}
}
for (i=0; i<ligne; i++) {
printf("|");
for (j=0; j<colonne; j++) {
printf("%d",mat[i][j]);
if (j<colonne-1) {
printf(",");
}
}
printf("|\n");
}
return 0;
}
#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[])
{
int degre,i;
char poly[50];
printf("Quel degre : ");
scanf("%d", °re);
int coef[degre];
printf("\n");
for (i=0; i<degre; i++) {
printf("Rentrez la valeur du coefficient %d : ",i+1);
scanf("%d", &coef[i]);
sprintf(poly, "X^%d", coef[i]);
if (i < degre-1) {
strcat(poly, "X");
strcat(poly, " + ");
}else if (i != degre){
sprintf(poly, "X^%d", degre-i);
strcat(poly, " + ");
}
}
printf("%s", poly);
return 0;
}