Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

1.

Ndertoni nje program ne gjuhen c qe llogarit shumen e meposhtme:


3*2 + 5*6 + 7*30 + 9*210+
Fillimi
lexo n

I=3
S=0
b=2
b= i*b
S=S+b
I = I +2

i<= 2*n+1

Po

Jo
Fund

Shenim: Kushti duhet i<=2*n+1 sepse per n=1, i=3, per n=2, i=5, per n=3, i=7 etj. Pra
rasti i pergjithshem eshte i=2*n+1

Kodi ne gjuhen c
# include <stdio.h>
int main (void){
int i, n, s=0, b=2;
printf("Jepni numrin e kufizave qe doni te llogarisni shumen:");
scanf ("%d", &n);
for (i=3;i<=2*n+1;i=i+2)
{
b=i*b;
s=s+b;
}
printf("Shuma eshte: %d",s);
}

2. Ndertoni nje program ne gjuhen c qe llogarit shumen e meposhtme:


3*2 + 6*4 + 24*8 + 192*16
Fillimi
lexo n

I=2
S=0
b=3
b= i*b
S=S+b
I = 2i

i<= 2^n

Po

Jo
Fund

Shenim: Kushti duhet i<=2^n sepse per n=1, i=2, per n=2, i=4, per n=3, i=8, per n=4,
i=16 etj. Pra rasti i pergjithshem eshte i=2^n

Kodi ne gjuhen c
# include <stdio.h>
int main (void){
int i,n, s=0, b=3;
printf("Jepni numrin e kufizave qe doni te llogarisni shumen:");
scanf ("%d", &n);
for (i=2;i<=pow(2,n);i=i*2) // i<=2^n
{
b=i*b;
s=s+b;
}
printf("Shuma eshte: %d",s);
}

You might also like