[go: up one dir, main page]

0% found this document useful (0 votes)
24 views7 pages

C Programming Exercises

The document contains code for several C programs that calculate Fibonacci sequences, sum integers, calculate powers of 4, and calculate squares and cubes of user-input numbers. The first program calculates the Fibonacci sequence up to 10000. The second calculates the Fibonacci sequence up to the 50th term. Other programs sum integers from 1 to a user-input number, calculate powers of 4 up to 30, and calculate squares and cubes of 5 user-input numbers.

Uploaded by

Javier Balsas
Copyright
© © All Rights Reserved
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)
24 views7 pages

C Programming Exercises

The document contains code for several C programs that calculate Fibonacci sequences, sum integers, calculate powers of 4, and calculate squares and cubes of user-input numbers. The first program calculates the Fibonacci sequence up to 10000. The second calculates the Fibonacci sequence up to the 50th term. Other programs sum integers from 1 to a user-input number, calculate powers of 4 up to 30, and calculate squares and cubes of 5 user-input numbers.

Uploaded by

Javier Balsas
Copyright
© © All Rights Reserved
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/ 7

Fibonacci a:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int f1=1, f2=1;

printf("0\n1\n",f1);

while(f1<10000) {

printf("%d\n",f2);
f2+=f1;
f1=f2-f1;
}

system("PAUSE");
return 0;
}

Fibonacci b:
#include <stdio.h>

#include <stdlib.h>

int main(void)

int x,y,z,cont;

x=0;

y=1;

printf("0\n1\n",z);

for (cont=1;cont<=50;cont=cont+1)

z=x+y;

printf("%d\n",z);

x=y;

y=z;

system("PAUSE");

return 0;

}
1.. introduce dos nmeros y los sumas y pregunta.

#include <stdio.h>

#include <stdlib.h>

int main(void)

int n1, n2;

char op;

do{

system("cls");

printf("\nDame dos numero: \n");

scanf( "%d", &n2);

scanf( "%d", &n1);

n1=n1+n2;

printf("\nResultado %d",n1);

printf("\nDesea introducir otro numero, s/n");

fflush( stdin );

scanf( "%c", &op);

}while(op!= 'n' && op!= 'N' );

return 0;

}
2.imprime n nmeros enteros

#include <stdio.h>

#include <stdlib.h>

int main(void)

int i,s=0,n;

printf("\nDame un numero: \n");

scanf( "%d", &n);

for(i=1;i<=n;i++) {

s=s+i;

printf("\nResultado %d",s);

system("pause");

return 0;

}
1. Potencia de 4

#include <stdio.h>

#include <math.h>

int main(){

int sum=0,pot;

int i,c=0;

while(c<=30){

c++;

pot=pow(4, c);

printf("\nPotencia %d",pot);

return 0;

}
2.. pide 5 numeros y busca el cuadrado y el cubo

#include <stdio.h>

#include <math.h>

int main(){

int n1,n2, i;

for(i=1;i<=5;i++){

printf("\nDame un numero para buscar el cuadrado: \n");

scanf( "%d", &n1);

printf("\nDame un numero para buscar el cubo: \n");

scanf( "%d", &n2);

n1=pow(n1, 2);

n2=pow(n2, 3);

printf("\nPotencia %d",);

}
return 0;

You might also like