diogoAlves

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

May 3rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.47 KB | None | 0 0
  1. //IFF - Programação Estruturada
  2. //Lista de Exercícios 0 - Exercício 6
  3.  
  4. #include<stdio.h>
  5. #include<math.h>
  6.  
  7. float calcularS(int a, int n){
  8.     float s=0;
  9.     for(int x=1;x<=n;x++){
  10.         s+=x/pow(a,x);
  11.     }
  12.     return s;
  13. }
  14.  
  15. int main(){
  16.     setbuf(stdout,NULL);
  17.     int a=0, n=0;
  18.     printf("Entre com o valor de a: ");
  19.     scanf("%d",&a);
  20.     do{
  21.         printf("Entre com o valor de n, sendo n maior ou igual a 1: ");
  22.         scanf("%d",&n);
  23.     }while(n<1);
  24.     printf("S=%.3f",calcularS(a,n));
  25. }
Advertisement
Add Comment
Please, Sign In to add comment