Programa en C++: Suma de notas & Actividades
Usiel Vela
16:59
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main()
{
int carnet, acts[20], p1, p2, pj, ef, i, suma, acumulador;
char nom[30], apell[30], linea[300], *tmp;
do {
printf("\nIngrese Carnet: ");
scanf("%d", &carnet);
printf("\nIngrese Nombre: ");
scanf("%s", nom);
printf("\nIngrese Apellido: ");
scanf("%s", apell);
printf("\nIngrese Nota p1: ");
scanf("%d", &p1);
printf("\nIngrese Nota p2: ");
scanf("%d", &p2);
printf("\nIngrese Nota Proyecto: ");
scanf("%d", &pj);
printf("\nIngrese Nota Examen final: ");
scanf("%d", &ef);
fflush(stdin);
//leer 20 notas
memset(acts, 0, sizeof(int)*20);
printf("\nIngrese veinte notas separadas por espacios o comas: ");
gets(linea);
tmp = strtok(linea, " ,");
i = 0;
suma = 0;
while(tmp!= NULL && i<20) {
sscanf(tmp, "%d", &acts[i]);
printf("%d\n", acts[i]);
suma+= acts[i++];
tmp = strtok(NULL, " ,");
}
printf("%d===\n", suma);
acumulador = p1 + p2 + pj + ef + suma;
printf("La nota final es %d\n", acumulador);
printf("Desea introducir más datos? (y/n)");
} while(tolower(getchar())=='y');
system("PAUSE");
return 0;
}
0 Comentarios