diogoAlves

IFF/Programação Estruturada/Lista 0/Exercício 8

May 3rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. //IFF - Programação Estruturada
  2. //Lista de Exercícios 0 - Exercício 8
  3. #include<stdio.h>
  4.  
  5. int calcularP(int b, int n){
  6.     int p=0;
  7.     for(int x=1;x<=n;x++){
  8.         if(x==1){
  9.             p=x+b;
  10.         }else{
  11.         if((x%2)==0) p*=x-b; else p*=x+b;
  12.         }
  13.     }
  14.     return p;
  15. }
  16.  
  17. int main(){
  18.     setbuf(stdout,NULL);
  19.     int b, n;
  20.     printf("Entre com os valores de b e n respectivamente: ");
  21.     scanf("%d%d",&b,&n);
  22.     printf("P=%d",calcularP(b,n));
  23. }
Advertisement
Add Comment
Please, Sign In to add comment