Në këtë tutorial ju do të mësoni fillet e programimit me C++. Ketu bëhet fjalë për cikle të ndryshme duke përfshirë edhe serinë Fibonaqi te bërë me anë të ciklit do-while.

Në këtë tutorial ju do të mësoni fillet e programimit me C++. Ketu bëhet fjalë për cikle të ndryshme duke përfshirë edhe serinë Fibonaqi.

// Mesimi1.cpp : Percakton piken hyrese per aplikacion konzolle.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <time.h>
#include <stdio.h>
#include <iomanip>

using namespace std;

class Fibonacci {
public:
	int a, b, c;
	void generate(int);
};

void Fibonacci::generate(int n) {
	a = 0; b = 1;
	cout << a << " " << b;
	for (int i = 1; i <= n - 2; i++) {
		c = a + b;
		cout << " " << c;
		a = b;
		b = c;
	}
}
int _tmain(int argc, _TCHAR* argv[])
{

	float x;        //	
	float y;        //deklarimi i ndryshoreve	
	float n;        //	
	int b;
	int i = 0;
	b = 1;            //e vendos vleren e b-se ne 1	
	cout << 
"Mbledhja e dy numrave, qe ta nderpreni ciklin shtypni -1 " << endl;
	while (b != -1)    //krijo nje unaze qe programi te 
//punoje gjersa personi deshiron te shtoje numra
	{
		//kodi ne vijim u jep perdoruesit te shtoje 
//dy numra dhe te thirre funksioni shtojce qe te paraqet rezultatet
		cout << "Jep numrin x = ";
		cin >> x;
		cout << "Jep numrin y = ";
		cin >> y;

		n = (x + y);

		cout << "Rezultati i n = " << n << endl;

		//Kodi ne vjim e vendos b ne vleren e 
//dhene nga e hyra e perdoruesit qe ta percaktoje nese 
// unaza eshte e thyer qe te perfundoje programi, 
//me vleren -1 dilet nga unaza while

		cout << "Vazhdimi, [-1] të ndërpritet "; 

		cin >> b; //vendoset vlera e dhene ne b

		cout << "Vlera e b =" << b << endl;

		if (b == 2)
		cout << "Vlera e dhene eshte e barabarte me 2" 
                             << endl;

	}
	cout << endl;
	system("pause");
	cout << endl;
	cout << "Listimi i numrave nga nje deri ne 10" << endl;
	for (i = 0; i < 10; i++) {
		cout << "Numri " << i << " vlera " << i << endl;
	}
	cout << endl;
	system("pause");
	cout << endl;
	cout << "Anashkalimi i nje cikli" << endl;

	for (i = 0; i < 10; i++) {
		if (i == 5) { cout << endl; continue; };

		cout << "Vlera e " << i << endl;

	}
	cout << endl;
	system("pause");
	cout << endl;
	cout << "Ndalimi i qarkullimit ne unaze ne numer te dhene" 
        << endl;

	for (i = 0; i < 10; i++) {

		if (i == 5) break;

		cout << "Vlera e " << i << endl;

	}
	cout << endl;
	system("pause");
	cout << endl;
	cout << "Listimi i mbrapshte" << endl;
	for (i = 10; i >= 0; i--) {

		cout << "Vlera e " << i << endl;

	}
	cout << endl;
	system("pause");
	cout << endl;
	cout << "Ndarja e numrave ne çift dhe tek" << endl;
	cout << endl;
	int sumTek = 0, sumCift = 0, countTek = 0, countCift = 0; 
// Deklarimi dhe inicializimi i vlerave me numer te plote


	for (i = 0; i < 10; i++) {
		if (i % 2 == 0) {
			countCift++; // rritja e numrit per nje
			sumCift += i;//
		}
		else
		{
			countTek++; // rritja e numrit per nje
			sumTek += i; //
		}

		 

	}
	cout << endl;
	system("pause");
	cout << endl;
	printf_s("Shumat: %d cift, %d tek\nNumri %d cift, %d tek", 
            sumCift, sumTek, countCift, countTek);
	cout << endl;
	system("pause");
	cout << endl;

	cout << "Serite Fibonaci" << endl;
	cout << "Shkruaj numrin e termeve qe ju duhen ne seri: ";
	int n1;
	cin >> n1;
	Fibonacci fibonacci;
	fibonacci.generate(n1);
	cout << endl;
	system("pause");
	return 0;
}

 

Kodi i projekti në C++ të VS C++ 2014 si dhe GNU CC

Published by amurati

I am a software developer, translator and poetry writer soon also a novel to be turned into a movie

Leave a comment

Please log in using one of these methods to post your comment:

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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: