Différences entre versions de « C algo td4 »
Aller à la navigation
Aller à la recherche
| Ligne 1 : | Ligne 1 : | ||
<pre> | <pre> | ||
| + | // | ||
| + | // main.c | ||
| + | // Exercice 1.1 | ||
| + | // | ||
| + | // Created by Hugo on 12/03/2014. | ||
| + | // Copyright (c) 2014 Hugo. All rights reserved. | ||
| + | // | ||
| + | |||
#include <stdio.h> | #include <stdio.h> | ||
| − | |||
| − | int main() { | + | int main(int argc, const char * argv[]) |
| − | int ligne, colonne, i, j; | + | { |
| − | printf("Combien de lignes: "); | + | int ligne,colonne,i,j; |
| + | |||
| + | printf("Combien de lignes : "); //Le nombe de colonnes pour la matrice voulue | ||
scanf("%d", &ligne); | scanf("%d", &ligne); | ||
| − | printf("Combien de | + | printf("Combien de colonnes : "); //Le nombre de colonnes pour la matrice voulue |
scanf("%d", &colonne); | scanf("%d", &colonne); | ||
| − | + | ||
| − | + | int sqc=ligne+colonne-1, sequence[sqc]; | |
| − | + | int mat[ligne][colonne]; | |
| − | printf(" | + | |
| − | scanf("%d", & | + | printf("\n"); |
| − | + | ||
| − | + | for (i=0; i<sqc; i++) { //On connait le nombre de séquence c'est "sqc" | |
| − | for(j=0; j < | + | printf("Rentrez la valeur de l'index %d : ",i+1); |
| − | if(i == 0){ | + | scanf("%d", &sequence[i]); //On rentre les valeurs de la matrice |
| − | mat[i][j] = | + | } |
| + | |||
| + | for (i=0; i<ligne; i++) { | ||
| + | for (j=0; j<colonne; j++) { | ||
| + | if (i==0) { | ||
| + | mat[i][j]=sequence[j]; | ||
}else{ | }else{ | ||
if(j == 0){ | if(j == 0){ | ||
| − | mat[i][j] = | + | mat[i][j]=sequence[colonne+i-1]; |
}else{ | }else{ | ||
| − | + | mat[i][j]=mat[i-1][j-1]; | |
} | } | ||
} | } | ||
} | } | ||
| − | + | } | |
| − | + | for (i=0; i<ligne; i++) { | |
| − | + | printf("|"); | |
| − | for(j=0; j < | + | for (j=0; j<colonne; j++) { |
| − | + | printf("%d",mat[i][j]); | |
| − | + | if (j<colonne-1) { | |
| − | + | printf(","); | |
| − | + | } | |
} | } | ||
printf("|\n"); | printf("|\n"); | ||
| − | + | } | |
| − | + | ||
| + | |||
| + | return 0; | ||
} | } | ||
</pre> | </pre> | ||
Version du 12 mars 2014 à 11:24
//
// main.c
// Exercice 1.1
//
// Created by Hugo on 12/03/2014.
// Copyright (c) 2014 Hugo. All rights reserved.
//
#include <stdio.h>
int main(int argc, const char * argv[])
{
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;
}