Zgjidhja e Ushtrimeve te Leksionit 9

Një zgjidhje e ushtrimeve të leksionit 9 :

Ushtrimi 1:

#include<stdio.h>
#include<conio.h>
void njehsimvektori(int t[],int n){
int i;
for(i=0;i<n;i++){
printf(“Jep elementin e %d te vektorit : “,i+1);
scanf(“%d”,&t[i]);
}
}
void funksion(int b[],int c){
int min=999,shuma=0,poz;
for(int i=0;i<c;i++){
shuma=b[i]+b[i+1];
if(shuma<min){
poz=i+1;
min=shuma;
}
}
printf(“Shuma me e vogel eshte %d.\nPozicioni i elementeve eshte: %d , %d .”,min,poz,poz+1);
}
int main(){
int n;
printf(“Jep madhesine e vektorit : “);
scanf(“%d”,&n);
int a[n];
njehsimvektori(a,n);
funksion(a,n);
getch();
return 0;
}

____________________________________

Ushtrimi 2:

#include<stdio.h>
#include<conio.h>
void njehsimvektori(int t[],int n){
int i;
for(i=0;i<n;i++){
printf(“Jep elementin e %d te vektorit : “,i+1);
scanf(“%d”,&t[i]);
}
}
void afishimvektori(int t[],int n){
for(int j=0;j<n;j++){
printf(“Elementi i %d i vektorit eshte : %d”,j+1,t[j]);
printf(“\n”);
}
}
void funksion (int a[],int b[],int n,int m){
int k,l=-1;
int c[k];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
if(a[i]==b[j]){
l++;
c[l]=a[i];
}
k=l+1;
}
if(k>0){
printf(“\nElementet e perbashket te vektoreve jane : \n”);
afishimvektori(c,k);
}
else printf(“\nS’ka elemente te perbashket!”);
}
int main(){
int n,m;
printf(“Jep madhesine e vektorit te pare : “);
scanf(“%d”,&n);
int a[n];
njehsimvektori(a,n);
printf(“Jep madhesine e vektorit te dyte : “);
scanf(“%d”,&m);
int b[m];
njehsimvektori(b,m);
funksion(a,b,n,m);
getch();
return 0;
}

____________________________________

Ushtrimi 3 :

#include<stdio.h>
#include<conio.h>
void njehsimvektori(int t[],int n){
int i;
for(i=0;i<n;i++){
printf(“Jep elementin e %d te vektorit : “,i+1);
scanf(“%d”,&t[i]);
}
}
void afishimvektori(int t[],int n){
for(int j=0;j<n;j++){
printf(“Elementi i %d i vektorit eshte : %d”,j+1,t[j]);
printf(“\n”);
}
}
void funksion (int a[],int n){
int d,l=-1;
int c[d];
for(int i=0;i<n;i++){
if(a[i]!=a[i+1]){
l++;
c[l]=a[i];
}
d=l+1;
}
if(d>0){
printf(“\nElementet pa perseritje te vektorit jane : \n”);
afishimvektori(c,d);
}
else printf(“\nVektori nuk ka elemente!”);
}
int main(){
int n,m;
printf(“Jep madhesine e vektorit : “);
scanf(“%d”,&n);
int v[n];
njehsimvektori(v,n);
funksion(v,n);
getch();
return 0;
}

____________________________________

Ushtrimi 4 :

#include<stdio.h>
#include<conio.h>
int main(){
int n, c;
printf(“Fut te dhena: “);
char a[100];
n=0;
while((c=getchar())!=’\n’){
if(n<100)
a[n]=c;
n++;
}
printf(“U futen %d karaktere.”,n);
getch();
return 0;
}

____________________________________

Ushtrimi 5 :

#include <stdio.h>
#include<conio.h>
void njehsimvektori(int t[],int n){
int i;
for(i=0;i<n;i++){
printf(“Jep elementin e %d te vektorit : “,i+1);
scanf(“%d”,&t[i]);
}
}
void funksion(int a[],int b){
int shTek=0,shCift=0;
for(int i=0;i<b;++i){
if (i%2==0)shTek=shTek+a[i];
else shCift=shCift+a[i];
}
printf(“\nShuma e elementeve ne pozicione teke eshte %d.\n”, shTek);
printf(“\nShuma e elementeve ne pozicione cift eshte %d.\n”, shCift);
}
int main (){
int n;
printf(“Jep madhesine e vektorit: ” );
scanf(“%d”, &n);
int v[n];
njehsimvektori(v,n);
funksion(v,n);
getch();
return 0;
}

_____________________________________

Ushtrimi 6 :

#include<stdio.h>
#include<conio.h>
void njehsimvektori(int t[],int n){
int i;
for(i=0;i<n;i++){
printf(“Jep elementin e %d te vektorit : “,i+1);
scanf(“%d”,&t[i]);
}
}
void afishimvektori(int t[],int n){
for(int j=0;j<n;j++){
printf(“Elementi i %d i vektorit eshte : %d”,j+1,t[j]);
printf(“\n”);
}
}
void funksion(int c[],int d){
int a,b,nr=0;
printf(“\nJepni vleren e a :”);
scanf(“%d”,&a);
printf(“Jepni vleren e b :”);
scanf(“%d”,&b);
a=a-1;
b=b-1;
for (int i=0;i<d;++i)if(i>=a && i<b)nr++;
printf(“\nNumri i elementeve eshte %d.”,nr);
}

int main (){
int n;
printf(“Jepni madhesine e vektorit: ” );
scanf(“%d”, &n);
int v[n];
njehsimvektori(v,n);
funksion(v,n);
getch();
return 0;
}
___________________________________________

Ushtrimi 7 :

#include<stdio.h>
#include<conio.h>
void njehsimvektori(int t[],int n){
int i;
for(i=0;i<n;i++){
printf(“Jep elementin e %d te vektorit : “,i+1);
scanf(“%d”,&t[i]);
}
}
void afishimvektori(int t[],int n){
for(int j=0;j<n;j++){
printf(“Elementi i %d i vektorit eshte : %d”,j+1,t[j]);
printf(“\n”);
}
}
void funksion(int v[],int n){
int k=0,j=0;
int c[k],t[j];
for(int i=0;i<n;i++){
if(i%2!=0){
c[k]=v[i];
k++;
}
else{
t[j]=v[i];
j++;
}
}
if(k>0){
printf(“Vektori C :\n”);
afishimvektori(c,k);
}
else printf(“\nVektori C nuk ka elemente!\n”);
if(j>0){
printf(“Vektori T :\n”);
afishimvektori(t,j);
}
else printf(“\nVektori T nuk ka elemente!\n”);
}

int main (){
int n;
printf(“Jepni madhesine e vektorit: ” );
scanf(“%d”, &n);
int v[n];
njehsimvektori(v,n);
funksion(v,n);
getch();
return 0;
}

_____________________________________

Ushtrimi 8 :

#include<stdio.h>
#include<conio.h>
void njehsimvektori(int t[],int n){
int i;
for(i=0;i<n;i++){
printf(“Jep elementin e %d te vektorit : “,i+1);
scanf(“%d”,&t[i]);
}
}
void funksion(int v[],int n){
int x=0;
for(int i=0;i<n;i++){
if(v[i]<0){
printf(“Pozicioni i elementit te pare negativ eshte %d.”,i+1);
x++;
break;
}
}
if(x==0)printf(“Vektori nuk ka elemente negative!”);
}
int main (){
int n;
printf(“Jepni madhesine e vektorit: ” );
scanf(“%d”, &n);
int v[n];
njehsimvektori(v,n);
funksion(v,n);
getch();
return 0;
}

_____________________________________

Ushtrimi 9 :

#include<stdio.h>
#include<conio.h>
void njehsimvektori(int t[],int n){
int i;
for(i=0;i<n;i++){
printf(“Jep elementin e %d te vektorit : “,i+1);
scanf(“%d”,&t[i]);
}
}

void funksion(int v[],int n){
int max=v[0];
int nr=1;
for(int i=1;i<n;++i)
if(v[i]>max){
max=v[i];
nr=1;
}
else if(v[i]==max)nr++;
printf(“\nElementi maksimal i vektorit eshte %d dhe ndodhet %d here ne vektor .”, max,nr);
}
int main (){
int n;
printf(“Jepni madhesine e vektorit: ” );
scanf(“%d”, &n);
int v[n];
njehsimvektori(v,n);
funksion(v,n);
getch();
return 0;
}

_____________________________________

Ushtrimi 10 :

#include<stdio.h>
#include<conio.h>
void njehsimvektori(int t[],int n){
int i;
for(i=0;i<n;i++){
printf(“Jep elementin e %d te vektorit : “,i+1);
scanf(“%d”,&t[i]);
}
}
void afishimvektori(int t[],int n){
for(int j=0;j<n;j++){
printf(“Elementi i %d i vektorit eshte : %d”,j+1,t[j]);
printf(“\n”);
}
}
void funksion(int A[],int B[],int n){
int C[n];
for(int i=0; i<n; ++i)
C[i]=A[i]*B[i];
afishimvektori(C,n);
}
int main (){
int n,m;
printf(“Jepni madhesine e vektoreve: ” );
scanf(“%d”, &n);
int A[n];
int B[n];
printf(“\nNjehso vektorin A : \n”);
njehsimvektori(A,n);
printf(“\nNjehso vektorin B : \n”);
njehsimvektori(B,n);
printf(“\nVlerat e vektorit C jane : \n”);
funksion(A,B,n);
getch();
return 0;
}

_____________________________________

Studime të mbara!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: