Last active
December 12, 2015 01:08
-
-
Save dlion/4688615 to your computer and use it in GitHub Desktop.
Programmazione e laboratorio Prova pratica – 29 Gennaio 2013 Compito A
1) Date due successioni numeriche an e bn, la loro convoluzione è una successione il cui termine n-simo cn è dato da:
cn = a0bn + a1b(n -1) + ....+ a(n -1)b1 + anb0
Date le successioni
an = (n + 1)²
e bn = 1 / (n + 2)
si scriva una funzione in C che preso in input un intero n…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Prova d'esame di programmazione e laboratorio by Domenico Luciani aka DLion | |
* 01/02/13 - 03:17 | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
void convoluzione(int); | |
int main() | |
{ | |
int n; | |
printf("Inserisci n: "); | |
scanf("%d",&n); | |
convoluzione(n); | |
return 0; | |
} | |
void convoluzione(int n) | |
{ | |
int i,j; | |
float *a = (float*)malloc(n*sizeof(float)); | |
float *b = (float*)malloc(n*sizeof(float)); | |
float *ris = (float*)malloc(n*sizeof(float)); | |
puts("--- Stampo an ---"); | |
for(i=1; i <= n; i++) | |
{ | |
a[i-1] = (i+1.)*(i+1.); | |
printf("%d: %2.2f ",i,a[i-1]); | |
} | |
puts("\n--- Stampo bn ---"); | |
for(i=1; i <= n; i++) | |
{ | |
b[i-1] = 1./(i+2.); | |
printf("%d: %2.2f ",i,b[i-1]); | |
} | |
puts("\n--- Stampo la convoluzione di an e bn ---"); | |
for(i=0; i < n; i++) | |
{ | |
for(j=0; j <= i; j++) | |
ris[i] += a[j] * b[i-j]; | |
printf("%d: %2.2f ",i+1,ris[i]); | |
} | |
putchar('\n'); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment