WELCOME TO C PROGRAMMING

#include<stdio.h>

int main(){ 
#include<stdio.h>

int main(){
int a[50],i,n;

printf("Vendos sa elemente doni te vendosni ne tabele:");
scanf("%d",&n);

for(i=0;i<n;i++){
printf("Vendos elementin e %d : ",i);
scanf("%d",&a[i]);
}

for(i=n;i>0;i--){

if(a[i]%10==0 && a[i]!=0){
printf("nNumri i fundit qe plotepjesohet me 10 eshte %d%d", a[i],i);
}
}
return 0;
}

#include<stdio.h>

int main(){
int a[50],x,n,i,j,count=0;
printf("Sa dini gjatesine e vektorit:");
scanf("%d",&n);

for(i=0;i<n;i++){
printf("Vendos elementin e %d",i);
scanf("%d",&a[i]);
}

printf("nVendos nr qe doni te kryeni plotepjestimi:");
scanf("%d",&x);

for(i=0;i<n;i++){
if(a[i]%x==0){
count=count+1;
}
}

printf( "%d plotepjesohen me nr %d",count,x);
return 0;
}

#include<stdio.h>

int main(){
int a[100],i;
int n=sizeof(a)/sizeof(a[0]);
printf("Sa ekemente doni te vendosni ne tabele:");
scanf("%d",&n);

for(i=0;i<n;i++){
printf("Vendos elementin e %d",i);
scanf("%d",&a[i]);
}

for(i = n-1; i>=0; i--)
{
printf("%dt", a[i]);
}

return 0;

}

#include<stdio.h>

int main(){
int a[100],i;
int n=sizeof(a)/sizeof(a[0]);
printf("Sa ekemente doni te vendosni ne tabele:");
scanf("%d",&n);

for(i=0;i<n;i++){
printf("Vendos elementin e %d",i);
scanf("%d",&a[i]);
}
for(i = n-1; i>=0; i--)
{
printf("%dt", a[i]);
}
/*for(i=n;i>0;i--){
printf("Tabela eshte %d",a[i]);
}*/
//printf("Tabela eshte %d",a[i]);
return 0;

}

#include <stdio.h>

void print(int arr[], int n)
{
int i;
for (i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
}

void reverse(int arr[], int n)
{
int aux[n];
int i;
for ( i = 0; i < n; i++) {
aux[n - 1 - i] = arr[i];
}

for ( i = 0; i < n; i++) {
arr[i] = aux[i];
}
}

int main(void)
{
int arr[] = { 1, 2, 3, 4, 5 };
int n = sizeof(arr)/sizeof(arr[0]);

reverse(arr, n);
print(arr, n);

return 0;
}

#include <stdio.h>
long llogarit_shumen(int [], int);

int main()
{
int n, c, array[100];
long result;

scanf("%d", &n);

for (c = 0; c < n; c++)
scanf("%d", &array[c]);

result = llogarit_shumen(array, n);

printf("Sum = %ldn", result);

return 0;
}

long llogarit_shumen(int a[], int n) {
static long sum = 0;

if (n == 0)
return sum;

sum = sum + a[n-1];

return llogarit_shumen(a, --n);
}

#include <stdio.h>

int main()
{
int n, sum = 0, i, value;

printf("Sa numra do te shtoni?n");
scanf("%d", &n);

printf("Vendos nr te plote %d n", n);

for (i = 1; i <= n; i++)
{
scanf("%d", &value);
sum = sum + value;
}

printf("Shuma e nr eshte = %dn", sum);

return 0;
}

#include<stdio.h>
main()
{
int i,size,pos=0,neg=0;
float avg;
printf("Vendos madhesine e arrayn");
scanf("%d",&size);
int array[size];
printf("Vendos nr per te gjet shumen e nr pozitiv dhe negativn");
for(i=0;i<size;i++)
{
scanf("%d",&array[i]);

}

for(i=0;i<size;i++)
{
if(array[i]>0)
pos+=array[i];
if(array[i]<0)
neg+=array[i];
}

printf("Shuma e nr pozitiv %dn",pos);
printf("Shuma e nr negativ %dn",neg);

}

#include<stdio.h>

int main()
{
int i,j,m,n,d1=0,d2=0,a[5][5];
int count;
float mes;
printf("Rrjeshtat dhe kolonat:");
scanf("%d%d",&m,&n);
printf("Elementet:n");

for(i=0;i<m;++i)
for(j=0;j<n;++j)
{
scanf("%d",&a[i][j]);
if(j>i)

d1+=a[i][j];
d2=a[i][j];

/* else
if(i>j)
d2+=a[i][j]; */
}

printf("Shuma siper diagonales=%dn",d1);

mes=d1/d2;
printf("Mes eshte =%.2fn",mes);

return 0;
}

/*Ushtrim 3:
Te ndertohet nje funksion rekursiv qe gjen prodhimin e N numrave tek.
Te ndertohet nje funskion rekursiv qe gjen prodhimin e N numrave cift.
Te ndertohet nje funksion rekursiv qe llogarit shumen e numrave qe fut perdoruesi nga tastjera deri ne momentin qe vlera e dhene prej tij eshte 100.
Te ndertohet nje funksion rekursiv qe merr si parameter nje vektor dhe kthen 1 nese elementet e vektorit te cilet jane vetem vlerat {0,1} jane te alternuara dhe 0 nese jo.*/

#include <conio.h>
#include <stdio.h>
#define m 4
int ciftProd(int n){
if(n==1) return 2;
else
return ciftProd(n-1)*(2*n);
}
int tekProd(int n)
{
if(n==1) return 1;
else
return tekProd(n-1)*(2*n-1);
}
int shVargRec(){
int n;
printf("nVendos vleren e n:");
scanf("%d",&n);
if(n==100) return 0;
else
return n+shVargRec();
}
int alternuar(int t[],int n){
if(n==1) return 1;
else
{
if(t[n-1]!=t[n-2])
return alternuar(t,n-1);
else
return 0;
}
}
int main(){

int a[m] = {1,0,1,0};
printf("nVargu:%d",ciftProd(2));
printf("nVargu:%d",tekProd(2));
printf("n Shuma:%d",shVargRec());
printf("n Alternuar: %d",alternuar(a,m));

getch();
return 0;
}

//Ushtrim 2: Te ndertohet nje funksion rekursiv qe kontrollon nese tabela t[n] eshte palindrome ose jo.
#include <stdio.h>
int palindrome(char t[],int begin,int end){
if((begin==end)||((begin+1==end)&&(t[begin]==t[end]))) return 1;
else
{
if(t[begin]==t[end]) return palindrome(t,begin+1,end-1);
else
return 0;
}

}

int main(){
char b[4] = {'a','b','c','a'};
printf("n Palindorme: %d",palindrome(b,0,3));
getch();
return 0;
}

#include <stdio.h>
int arraySortedCheck(int arr[], int n){

if (n == 1 || n == 0)
return 1;
if(arr[n-1] < arr[n-2])
return 0;
return arraySortedCheck(arr, n-1);
}
int main(int argc, char const *argv[]){
int arr[] = {1,3,3,4,7};
int n = sizeof(arr)/sizeof(arr[0]);
if(arraySortedCheck(arr, n)){
printf("Array eshte e renditur ne rendin e duhurn");
}
else
printf("Array nuk eshte e renditur ne rendin e duhurn");
return 0;
}

//5.Ndertoni nje funksion rekursiv i cili merr si parametra nje vektor v dhe madhesine e tij n
//dhe kthen 1 nese vektori eshte i renditur ne rendin rrites dhe 0 ne te kundert.

#include <stdio.h>
int renditur(int v[], int n){

if(n==1) {

printf("%d",1);
return 1; //nese vektori ka nje elemente eshte i renditur, kthen 1 (kusht ndalimi)
}
else if(n>1)
{ //nese ka me shume se 1 elemente
if(v[n-1]>v[n-2]) // krahasohen 2 elementet e fundit te vektorit nese jane ne rendin rrites
printf("%d",v[n]);
return renditur(v,n-1); // nese plotesohet kushti, therritet funks. rekursiv per te testuar renditjen e elementeve te v pa elementin e fundit
}
else{

return 0; //vektori nuk eshte ne rendin rrites, kthen 0 (kusht ndalimi)
}
}
int main(){
int n;
int v[]={45,2};
int renditur(int v[], int n);
printf("%d",v[n]);
return 0;
}

#include<stdio.h>
int main(){
int n,i=1,b,count=0,count1=0;
printf("vlera e nn");
scanf("%d",&n);
while(i<=n)
{
printf("Vendos nrn");
scanf("%d",&b);
if(b>=0)
count++;
else
count1++;
i++;
}
printf("Nr pozitiv jane: %d",count);
printf("Nr negativ jane: %d",count1);
return 0;
}

#include<stdio.h>

int main()
{
int i, j, rjeshta, kolona, T[10][10], x = 5,rez;

printf("n Vendosni nr e rrjeshtave dhe kolonave : ");
scanf("%d %d", &i, &j);

printf("n Vendosni elementen e matrix n");
for(rjeshta = 0; rjeshta < i; rjeshta++)
{
for(kolona = 0;kolona < j;kolona++)
{
scanf("%d", &T[rjeshta][kolona]);
}
}

for(rjeshta = 1; rjeshta < i; rjeshta++)
{
rez = rez%x==0;
}

printf("n Elementet qe plotpjestohen me x = %d", rez );

return 0;
}

#include <stdio.h>
#include <conio.h>

nrnegativ(int a[],int n)
{
int i;
printf("nVlerat negative ne array jane : ");
for(i=0; i<n; i++)
{

if(a[i] < 0)
{
printf("%d ",a[i]==0),"=0";
}
else
{
printf("%d ",a[i]);
}
}

}
int main()
{
int a[1000],i,n;

printf("Vendos madhesine e array : ");
scanf("%d", &n);

printf("Vendos elementet e array : ");
for(i=0; i<n; i++)
{
scanf("%d", &a[i]);
}

nrnegativ(a,n);

}

#include<stdio.h>

int main()
{
int i,N,shuma;

printf("vlera e n: ");
scanf("%d",&N);

/*shuma= 0*/
shuma=0;
for(i=1;i<=N;i++)
shuma= shuma+ i;

printf("Shuma e serise: %dn",shuma);

return 0;
}

#include<stdio.h>

int main(){
int cmimi[30];
int i,n;
char prod[30];
printf("Vendosni numrin e produkteve qe doni te listoni:");
scanf("%d",&n);

for(i=0;i<n;i++){
printf("Emri i produktit te %d : ",i);

scanf("%s",&prod);
printf("Vendosni cmimin e produktit %d : ",i);
scanf("%d",&cmimi[i]);
}

for(i=0;i<n;i++){
printf("Produkti %s:n ",prod);
printf("Cmimi i produktit %d: n",cmimi[i]);
}
return 0;
}

#include<stdio.h>

int llogMes(){
int nota[100],i,n,shuma,mesatarja;
shuma=0;
printf("Sa nota doni te vendosni: ");
scanf("%d",&n);
for(i=0;i<=n;i++){
printf("Vendosni note e %d :" ,i);
scanf("%d",¬a[i]);
shuma +=nota[i];
}
mesatarja=shuma/n;
printf("Mes eshte: %d " ,mesatarja);
}

int main(){
llogMes();
}

</code>

<code>

#include <stdio.h>

int main()
{
int numri, guess, tries = 0;
srand(time(0)); /* seed random number generator */
numri = rand() % 20 + 1; /* random number between 1 and 100 */

printf("Guess My Number Gamenn");

do
{
printf("Enter a guess between 1 and 20 : ");
scanf("%d", &guess);
tries++;

if (guess > numri)
{
printf("Too high!nn");
}
else if (guess < numri)
{
printf("Too low!nn");
}
else
{
printf("nCorrect! You got it in %d guesses!n", tries);
}

}while (guess != numri);

return 0;
}







int a[50],i,n;

printf("Vendos sa elemente doni te vendosni ne tabele:");
scanf("%d",&n);

for(i=0;i<n;i++){
printf("Vendos elementin e %d : ",i);
scanf("%d",&a[i]);
}

for(i=n;i>0;i--){

if(a[i]%10==0 && a[i]!=0){
printf("nNumri i fundit qe plotepjesohet me 10 eshte %d%d", a[i],i);
}
}
return 0;
}

</code>

#include<stdio.h>

int main(){
int a[50],x,n,i,j,count=0;
printf("Sa dini gjatesine e vektorit:");
scanf("%d",&n);

for(i=0;i<n;i++){
printf("Vendos elementin e %d",i);
scanf("%d",&a[i]);
}

printf("nVendos nr qe doni te kryeni plotepjestimi:");
scanf("%d",&x);

for(i=0;i<n;i++){
if(a[i]%x==0){
count=count+1;
}
}

printf( "%d plotepjesohen me nr %d",count,x);
return 0;
}

<code>

#include<stdio.h>

int main(){
int a[100],i;
int n=sizeof(a)/sizeof(a[0]);
printf("Sa ekemente doni te vendosni ne tabele:");
scanf("%d",&n);

for(i=0;i<n;i++){
printf("Vendos elementin e %d",i);
scanf("%d",&a[i]);
}

for(i = n-1; i>=0; i--)
{
printf("%dt", a[i]);
}

return 0;

}

</code>

<code>

#include<stdio.h>

int main(){
int a[100],i;
int n=sizeof(a)/sizeof(a[0]);
printf("Sa ekemente doni te vendosni ne tabele:");
scanf("%d",&n);

for(i=0;i<n;i++){
printf("Vendos elementin e %d",i);
scanf("%d",&a[i]);
}
for(i = n-1; i>=0; i--)
{
printf("%dt", a[i]);
}
/*for(i=n;i>0;i--){
printf("Tabela eshte %d",a[i]);
}*/
//printf("Tabela eshte %d",a[i]);
return 0;

}

</code>







<code>

#include <stdio.h>

void print(int arr[], int n)
{
int i;
for (i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
}

void reverse(int arr[], int n)
{
int aux[n];
int i;
for ( i = 0; i < n; i++) {
aux[n - 1 - i] = arr[i];
}

for ( i = 0; i < n; i++) {
arr[i] = aux[i];
}
}

int main(void)
{
int arr[] = { 1, 2, 3, 4, 5 };
int n = sizeof(arr)/sizeof(arr[0]);

reverse(arr, n);
print(arr, n);

return 0;
}

</code>







<code>

#include <stdio.h>
long llogarit_shumen(int [], int);

int main()
{
int n, c, array[100];
long result;

scanf("%d", &n);

for (c = 0; c < n; c++)
scanf("%d", &array[c]);

result = llogarit_shumen(array, n);

printf("Sum = %ldn", result);

return 0;
}

long llogarit_shumen(int a[], int n) {
static long sum = 0;

if (n == 0)
return sum;

sum = sum + a[n-1];

return llogarit_shumen(a, --n);
}

</code>







<code>

#include <stdio.h>

int main()
{
int n, sum = 0, i, value;

printf("Sa numra do te shtoni?n");
scanf("%d", &n);

printf("Vendos nr te plote %d n", n);

for (i = 1; i <= n; i++)
{
scanf("%d", &value);
sum = sum + value;
}

printf("Shuma e nr eshte = %dn", sum);

return 0;
}

</code>







<code>

#include<stdio.h>
main()
{
int i,size,pos=0,neg=0;
float avg;
printf("Vendos madhesine e arrayn");
scanf("%d",&size);
int array[size];
printf("Vendos nr per te gjet shumen e nr pozitiv dhe negativn");
for(i=0;i<size;i++)
{
scanf("%d",&array[i]);

}

for(i=0;i<size;i++)
{
if(array[i]>0)
pos+=array[i];
if(array[i]<0)
neg+=array[i];
}

printf("Shuma e nr pozitiv %dn",pos);
printf("Shuma e nr negativ %dn",neg);

}

</code>







<code>

#include<stdio.h>

int main()
{
int i,j,m,n,d1=0,d2=0,a[5][5];
int count;
float mes;
printf("Rrjeshtat dhe kolonat:");
scanf("%d%d",&m,&n);
printf("Elementet:n");

for(i=0;i<m;++i)
for(j=0;j<n;++j)
{
scanf("%d",&a[i][j]);
if(j>i)

d1+=a[i][j];
d2=a[i][j];

/* else
if(i>j)
d2+=a[i][j]; */
}

printf("Shuma siper diagonales=%dn",d1);

mes=d1/d2;
printf("Mes eshte =%.2fn",mes);

return 0;
}

</code>







<code>

/*Ushtrim 3:
Te ndertohet nje funksion rekursiv qe gjen prodhimin e N numrave tek.
Te ndertohet nje funskion rekursiv qe gjen prodhimin e N numrave cift.
Te ndertohet nje funksion rekursiv qe llogarit shumen e numrave qe fut perdoruesi nga tastjera deri ne momentin qe vlera e dhene prej tij eshte 100.
Te ndertohet nje funksion rekursiv qe merr si parameter nje vektor dhe kthen 1 nese elementet e vektorit te cilet jane vetem vlerat {0,1} jane te alternuara dhe 0 nese jo.*/

#include <conio.h>
#include <stdio.h>
#define m 4
int ciftProd(int n){
if(n==1) return 2;
else
return ciftProd(n-1)*(2*n);
}
int tekProd(int n)
{
if(n==1) return 1;
else
return tekProd(n-1)*(2*n-1);
}
int shVargRec(){
int n;
printf("nVendos vleren e n:");
scanf("%d",&n);
if(n==100) return 0;
else
return n+shVargRec();
}
int alternuar(int t[],int n){
if(n==1) return 1;
else
{
if(t[n-1]!=t[n-2])
return alternuar(t,n-1);
else
return 0;
}
}
int main(){

int a[m] = {1,0,1,0};
printf("nVargu:%d",ciftProd(2));
printf("nVargu:%d",tekProd(2));
printf("n Shuma:%d",shVargRec());
printf("n Alternuar: %d",alternuar(a,m));

getch();
return 0;
}

</code>







<code>

//Ushtrim 2: Te ndertohet nje funksion rekursiv qe kontrollon nese tabela t[n] eshte palindrome ose jo.
#include <stdio.h>
int palindrome(char t[],int begin,int end){
if((begin==end)||((begin+1==end)&&(t[begin]==t[end]))) return 1;
else
{
if(t[begin]==t[end]) return palindrome(t,begin+1,end-1);
else
return 0;
}

}

int main(){
char b[4] = {'a','b','c','a'};
printf("n Palindorme: %d",palindrome(b,0,3));
getch();
return 0;
}

</code>







<code>

#include <stdio.h>
int arraySortedCheck(int arr[], int n){

if (n == 1 || n == 0)
return 1;
if(arr[n-1] < arr[n-2])
return 0;
return arraySortedCheck(arr, n-1);
}
int main(int argc, char const *argv[]){
int arr[] = {1,3,3,4,7};
int n = sizeof(arr)/sizeof(arr[0]);
if(arraySortedCheck(arr, n)){
printf("Array eshte e renditur ne rendin e duhurn");
}
else
printf("Array nuk eshte e renditur ne rendin e duhurn");
return 0;
}

</code>




<code>

//5.Ndertoni nje funksion rekursiv i cili merr si parametra nje vektor v dhe madhesine e tij n
//dhe kthen 1 nese vektori eshte i renditur ne rendin rrites dhe 0 ne te kundert.

#include <stdio.h>
int renditur(int v[], int n){

if(n==1) {

printf("%d",1);
return 1; //nese vektori ka nje elemente eshte i renditur, kthen 1 (kusht ndalimi)
}
else if(n>1)
{ //nese ka me shume se 1 elemente
if(v[n-1]>v[n-2]) // krahasohen 2 elementet e fundit te vektorit nese jane ne rendin rrites
printf("%d",v[n]);
return renditur(v,n-1); // nese plotesohet kushti, therritet funks. rekursiv per te testuar renditjen e elementeve te v pa elementin e fundit
}
else{

return 0; //vektori nuk eshte ne rendin rrites, kthen 0 (kusht ndalimi)
}
}
int main(){
int n;
int v[]={45,2};
int renditur(int v[], int n);
printf("%d",v[n]);
return 0;
}

</code>

#include<stdio.h>
int main(){
int n,i=1,b,count=0,count1=0;
printf("vlera e nn");
scanf("%d",&n);
while(i<=n)
{
printf("Vendos nrn");
scanf("%d",&b);
if(b>=0)
count++;
else
count1++;
i++;
}
printf("Nr pozitiv jane: %d",count);
printf("Nr negativ jane: %d",count1);
return 0;
}

<code>

#include<stdio.h>

int main()
{
int i, j, rjeshta, kolona, T[10][10], x = 5,rez;

printf("n Vendosni nr e rrjeshtave dhe kolonave : ");
scanf("%d %d", &i, &j);

printf("n Vendosni elementen e matrix n");
for(rjeshta = 0; rjeshta < i; rjeshta++)
{
for(kolona = 0;kolona < j;kolona++)
{
scanf("%d", &T[rjeshta][kolona]);
}
}

for(rjeshta = 1; rjeshta < i; rjeshta++)
{
rez = rez%x==0;
}

printf("n Elementet qe plotpjestohen me x = %d", rez );

return 0;
}

</code>







<code>

#include <stdio.h>
#include <conio.h>

nrnegativ(int a[],int n)
{
int i;
printf("nVlerat negative ne array jane : ");
for(i=0; i<n; i++)
{

if(a[i] < 0)
{
printf("%d ",a[i]==0),"=0";
}
else
{
printf("%d ",a[i]);
}
}

}
int main()
{
int a[1000],i,n;

printf("Vendos madhesine e array : ");
scanf("%d", &n);

printf("Vendos elementet e array : ");
for(i=0; i<n; i++)
{
scanf("%d", &a[i]);
}

nrnegativ(a,n);

}

</code>







<code>

#include<stdio.h>

int main()
{
int i,N,shuma;

printf("vlera e n: ");
scanf("%d",&N);

/*shuma= 0*/
shuma=0;
for(i=1;i<=N;i++)
shuma= shuma+ i;

printf("Shuma e serise: %dn",shuma);

return 0;
}

</code>




<code>

#include<stdio.h>

int main(){
int cmimi[30];
int i,n;
char prod[30];
printf("Vendosni numrin e produkteve qe doni te listoni:");
scanf("%d",&n);

for(i=0;i<n;i++){
printf("Emri i produktit te %d : ",i);

scanf("%s",&prod);
printf("Vendosni cmimin e produktit %d : ",i);
scanf("%d",&cmimi[i]);
}

for(i=0;i<n;i++){
printf("Produkti %s:n ",prod);
printf("Cmimi i produktit %d: n",cmimi[i]);
}
return 0;
}

</code>







<code>

#include<stdio.h>

int llogMes(){
int nota[100],i,n,shuma,mesatarja;
shuma=0;
printf("Sa nota doni te vendosni: ");
scanf("%d",&n);
for(i=0;i<=n;i++){
printf("Vendosni note e %d :" ,i);
scanf("%d",¬a[i]);
shuma +=nota[i];
}
mesatarja=shuma/n;
printf("Mes eshte: %d " ,mesatarja);
}

int main(){
llogMes();
}

</code>




<code>

#include <stdio.h>

int main()
{
int numri, guess, tries = 0;
srand(time(0)); /* seed random number generator */
numri = rand() % 20 + 1; /* random number between 1 and 100 */

printf("Guess My Number Gamenn");

do
{
printf("Enter a guess between 1 and 20 : ");
scanf("%d", &guess);
tries++;

if (guess > numri)
{
printf("Too high!nn");
}
else if (guess < numri)
{
printf("Too low!nn");
}
else
{
printf("nCorrect! You got it in %d guesses!n", tries);
}

}while (guess != numri);

return 0;
}

</code>

 

Visited 156 times, 1 visit(s) today