xxxxxxxxxx
#include <stdio.h>
int main()
{
/* printf function displays the content that is
* passed between the double quotes.
*/
printf("Hello World");
return 0;
}
xxxxxxxxxx
#include <iostream>
#include <queue>
using namespace std;
struct Node{
int data;
struct Node* left, *right;
};
// Function to count the full Nodes in a binary tree
int fullcount(struct Node* node){
// Check if tree is empty
if (!node){
return 0;
}
queue<Node *> myqueue;
// traverse using level order traversing
int result = 0;
myqueue.push(node);
while (!myqueue.empty()){
struct Node *temp = myqueue.front();
myqueue.pop();
if (temp->left && temp->right){
result++;
}
if (temp->left != NULL){
myqueue.push(temp->left);
}
if (temp->right != NULL){
myqueue.push(temp->right);
}
}
return result;
}
struct Node* newNode(int data){
struct Node* node = new Node;
node->data = data;
node->left = node->right = NULL;
return (node);
}
int main(void){
struct Node *root = newNode(10);
root->left = newNode(20);
root->right = newNode(30);
root->left->left = newNode(40);
root->left->right = newNode(50);
root->left->left->right = newNode(60);
root->left->right->right = newNode(70);
cout <<"count is: "<<fullcount(root);
return 0;
}
xxxxxxxxxx
#include <iostream>
using namespace std;
int main()
{
int i, j, n, sum = 0, tsum;
cout << "\n\n Find the sum of the series (1) + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n):\n";
cout << "------------------------------------------------------------------------------------------\n";
cout << " Input the value for nth term: ";
cin >> n;
for (i = 1; i <= n; i++)
{
tsum = 0;
for (j = 1; j <= i; j++)
{
sum += j;
tsum += j;
cout << j;
if (j < i)
{
cout << "+";
}
}
cout << " = " << tsum << endl;
}
cout << " The sum of the above series is: " << sum << endl;
}
xxxxxxxxxx
#include <iostream>
#include <queue>
using namespace std;
struct Node{
int data;
struct Node* left, *right;
};
// Function to count the full Nodes in a binary tree
int fullcount(struct Node* node){
// Check if tree is empty
if (!node){
return 0;
}
queue<Node *> myqueue;
// traverse using level order traversing
int result = 0;
myqueue.push(node);
while (!myqueue.empty()){
struct Node *temp = myqueue.front();
myqueue.pop();
if (temp->left && temp->right){
result++;
}
if (temp->left != NULL){
myqueue.push(temp->left);
}
if (temp->right != NULL){
myqueue.push(temp->right);
}
}
return result;
}
struct Node* newNode(int data){
struct Node* node = new Node;
node->data = data;
node->left = node->right = NULL;
return (node);
}
int main(void){
struct Node *root = newNode(10);
root->left = newNode(20);
root->right = newNode(30);
root->left->left = newNode(40);
root->left->right = newNode(50);
root->left->left->right = newNode(60);
root->left->right->right = newNode(70);
cout <<"count is: "<<fullcount(root);
return 0;
}
xxxxxxxxxx
#include <bits/stdc++.h>
using namespace std;
int recurFunct(int n)
{
if (n==1)
return 1;
return recurFunct(n-1) + 2*n-1;
}
int main()
{
int n;
cin>>n;
for (int i=2; i<=n+1; i++)
{
cout<<recurFunct(i)<<" ";
if (i%8 ==0 )
cout<<"\n";
}
return 0;
}
xxxxxxxxxx
#include<bits/stdc++.h>
using namespace std;
void printWords(string str)
{
// word variable to store word
string word;
// making a string stream
stringstream iss(str);
// Read and print each word.
while (iss >> word){
reverse(word.begin(),word.end());
cout<<word<<" ";
}
}
// Driver code
int main()
{
string s = "GeeksforGeeks is good to learn";
printWords(s);
return 0;
}
// This code is contributed by Nikhil Rawat
xxxxxxxxxx
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
float srednia, suma=0;
int ilosc_liczb=0;
int liczba;
cout<<"program obliczajacy srednia liczb parzystych (0 – konczy wpis): "<<endl;
do
{
cout<<"Podaj liczbe: ";
cin>>liczba;
if (liczba%2!=0 && liczba!=0) // jesli liczba jest nieparzysta
{
cout<<"Podaj liczbe: ";
cin>>liczba;
}
if (liczba!=0) //jesli liczba jest jakakolwiek liczba parzysta
{
suma=suma+liczba;
ilosc_liczb++;
}
}
while(liczba!=0);
srednia=suma/ilosc_liczb;
cout<<"Srednia: "<<srednia;
getch();
return 0;
}
xxxxxxxxxx
#include <bits/stdc++.h>
using namespace std;
// Function to check if elements are
// pairwise consecutive in queue
bool pairWiseConsecutive(queue<int> q)
{
// Transfer elements of q to aux.
stack<int> aux;
while (!q.empty()) {
aux.push(q.front());
q.pop();
}
// Again transfer the
// elements of aux to aux2
stack<int> aux2;
while (!aux.empty()) {
aux2.push(aux.top());
aux.pop();
}
// Traverse aux2 and see if
// elements are pairwise
// consecutive or not. We also
// need to make sure that original
// content is retained.
bool result = true;
while (aux2.size() > 1) {
// Fetch current top two
// elements of aux2 and check
// if they are consecutive.
int x = aux2.top();
aux2.pop();
int y = aux2.top();
aux2.pop();
if (abs(x - y) != 1)
result = false;
// Push the elements to queue
q.push(x);
q.push(y);
}
if (aux2.size() == 1)
q.push(aux2.top());
return result;
}
// Driver program
int main()
{
// Pushing elements into the queue
queue<int> q;
q.push(4);
q.push(5);
q.push(-2);
q.push(-3);
q.push(11);
q.push(10);
q.push(5);
q.push(6);
if (pairWiseConsecutive(q))
cout << "Yes" << endl;
else
cout << "No" << endl;
// Printing the original queue
while (!q.empty()) {
cout << q.front() << " ";
q.pop();
}
cout << endl;
return 0;
}