0% found this document useful (0 votes)
12 views5 pages

Int Main (Int X Do (: A) #Include

The document contains 6 code snippets written in C programming language. Each snippet includes input/output operations using scanf() and printf() functions. The snippets demonstrate: 1) reading input until a zero is entered; 2) calculating a sum of inputs in a for loop; 3) calculating a sum in a do-while loop and printing it.

Uploaded by

Jesse Sobenis
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

Int Main (Int X Do (: A) #Include

The document contains 6 code snippets written in C programming language. Each snippet includes input/output operations using scanf() and printf() functions. The snippets demonstrate: 1) reading input until a zero is entered; 2) calculating a sum of inputs in a for loop; 3) calculating a sum in a do-while loop and printing it.

Uploaded by

Jesse Sobenis
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

a) #include <stdio.h> int main(){ int x; do{ scanf("%i",&x); }while(x!

=0); }

b)

#include <stdio.h> main() { int x; int suma=0; for(int i=1; i<=8; i++) { printf("introdusca 8 numero="); scanf("%i",&x); suma+=x; } printf ("Suma= %i",suma); }

c) #include <stdio.h> int main(){ int x; int suma=0; do{ scanf("%i",&x); suma+=x; }while (x!=0); printf ("Suma= %i",suma); } d) #include <stdio.h> int main(){ int x; int suma=0,resp=0; do{ scanf("%i",&x); suma+=x; }

while (x!=0); printf ("Suma= %i",suma); printf("\nDesea continuar (S/N)?)"); scanf("%c",&resp); while (resp!='N' && resp!='n'); }

e) #include <stdio.h> int main(){ int i,suma=0,cont=0; do{ printf("\nNmero: "); scanf("%i",&i); suma+=i; if (i!=0) cont++; }while (i!=0); if(cont!=0) printf("\nMedia: %5.2f",(float)suma/cont); else printf("\nNo hubo nmeros"); }

f) #include <stdio.h> int main(){ int n; double precio, total=0; do{ do{ printf("\nIntroduzca la cantidad vendida: "); scanf("%d",&n); if(n<0) printf("Cantidad no valida"); }while(n<0); if (n>0){ printf("Introduzca el precio: "); do{ scanf("%lf",&precio); if(precio<0) printf("Precio no valido"); else total+=n*precio; }while(precio<0); }

}while(n!=0); printf("Total vendido = %.2f", total); }

You might also like