// Addition of two numbers
#include <iostream>
int main() {
int num1, num2, sum;
std::cout << "Enter two numbers: ";
std::cin >> num1 >> num2;
sum = num1 + num2;
std::cout << "Sum: " << sum << std::endl;
return 0;
} // see t.me/CPP_Coding/46
#include <iostream>
int main() {
int num1, num2, sum;
std::cout << "Enter two numbers: ";
std::cin >> num1 >> num2;
sum = num1 + num2;
std::cout << "Sum: " << sum << std::endl;
return 0;
} // see t.me/CPP_Coding/46
// factorial
#include <iostream>
int main() {
int n;
unsigned long long factorial = 1;
std::cout << "Enter a positive integer: ";
std::cin >> n;
for (int i = 1; i <= n; ++i) {
factorial *= i;
}
std::cout << "Factorial of " << n << " = " << factorial << std::endl;
return 0;
} // see t.me/CPP_Coding/46
#include <iostream>
int main() {
int n;
unsigned long long factorial = 1;
std::cout << "Enter a positive integer: ";
std::cin >> n;
for (int i = 1; i <= n; ++i) {
factorial *= i;
}
std::cout << "Factorial of " << n << " = " << factorial << std::endl;
return 0;
} // see t.me/CPP_Coding/46
// Fibonacci series
#include <iostream>
int main() {
int n, num1 = 0, num2 = 1, nthTerm;
std::cout << "Enter the number of terms: ";
std::cin >> n;
std::cout << "Fibonacci Series: ";
for (int i = 1; i <= n; ++i) {
std::cout << num1 << " ";
nthTerm = num1 + num2;
num1 = num2;
num2 = nthTerm;
}
return 0;
} // see t.me/CPP_Coding/46
#include <iostream>
int main() {
int n, num1 = 0, num2 = 1, nthTerm;
std::cout << "Enter the number of terms: ";
std::cin >> n;
std::cout << "Fibonacci Series: ";
for (int i = 1; i <= n; ++i) {
std::cout << num1 << " ";
nthTerm = num1 + num2;
num1 = num2;
num2 = nthTerm;
}
return 0;
} // see t.me/CPP_Coding/46
// String functions in c++ part 1
#include <iostream>
#include <string>
using namespace std;
int main() {
string str = "Hello, World!";
// length()
int length = str.length();
cout << "Length of the string: " << length << endl;
// substr()
string substring = str.substr(0, 5);
cout << "Substring: " << substring << endl;
// find()
int index = str.find("World");
cout << "'World' found at index: " << index << endl;
// compare()
string str2 = "Hello, World!";
int compareResult = str.compare(str2);
if(compareResult == 0)
cout << "Strings are equal." << endl;
else
cout << "Strings are not equal." << endl;
// append()
string appendedString = str.append(" Welcome!");
cout << "Appended string: " << appendedString << endl;
// replace()
str.replace(7, 5, "Universe");
cout << "Replaced string: " << str << endl;
// erase()
str.erase(0, 7);
cout << "Erased string: " << str << endl;
// insert()
str.insert(0, "Hello, ");
cout << "Inserted string: " << str << endl;
// find_first_of()
int firstIndex = str.find_first_of("lo");
cout << "First occurrence of 'lo' at index: " << firstIndex << endl;
// find_last_of()
int lastIndex = str.find_last_of("lo");
cout << "Last occurrence of 'lo' at index: " << lastIndex << endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main() {
string str = "Hello, World!";
// length()
int length = str.length();
cout << "Length of the string: " << length << endl;
// substr()
string substring = str.substr(0, 5);
cout << "Substring: " << substring << endl;
// find()
int index = str.find("World");
cout << "'World' found at index: " << index << endl;
// compare()
string str2 = "Hello, World!";
int compareResult = str.compare(str2);
if(compareResult == 0)
cout << "Strings are equal." << endl;
else
cout << "Strings are not equal." << endl;
// append()
string appendedString = str.append(" Welcome!");
cout << "Appended string: " << appendedString << endl;
// replace()
str.replace(7, 5, "Universe");
cout << "Replaced string: " << str << endl;
// erase()
str.erase(0, 7);
cout << "Erased string: " << str << endl;
// insert()
str.insert(0, "Hello, ");
cout << "Inserted string: " << str << endl;
// find_first_of()
int firstIndex = str.find_first_of("lo");
cout << "First occurrence of 'lo' at index: " << firstIndex << endl;
// find_last_of()
int lastIndex = str.find_last_of("lo");
cout << "Last occurrence of 'lo' at index: " << lastIndex << endl;
return 0;
}
👍1
//String functions in c++ part 2
#include <iostream>
#include <string>
using namespace std;
int main() {
string str = "Hello, World!";
// upper_case()
for(int i=0; i<str.length(); i++)
str[i] = toupper(str[i]);
cout << "Uppercase string: " << str << endl;
// lower_case()
for(int i=0; i<str.length(); i++)
str[i] = tolower(str[i]);
cout << "Lowercase string: " << str << endl;
// empty()
bool isEmpty = str.empty();
cout << "Is string empty? " << (isEmpty ? "Yes" : "No") << endl;
// front()
char frontChar = str.front();
cout << "First character: " << frontChar << endl;
// back()
char backChar = str.back();
cout << "Last character: " << backChar << endl;
// c_str()
const char* cString = str.c_str();
cout << "C-style string: " << cString << endl;
// stoi()
string numericString = "12345";
int numericValue = stoi(numericString);
cout << "Numeric value: " << numericValue << endl;
// to_string()
int intValue = 98765;
string strValue = to_string(intValue);
cout << "String value: " << strValue << endl;
// resize()
str.resize(5);
cout << "Resized string: " << str << endl;
// clear()
str.clear();
cout << "Cleared string: " << str << endl;
return 0;
} // see t.me/CPP_Coding/46
#include <iostream>
#include <string>
using namespace std;
int main() {
string str = "Hello, World!";
// upper_case()
for(int i=0; i<str.length(); i++)
str[i] = toupper(str[i]);
cout << "Uppercase string: " << str << endl;
// lower_case()
for(int i=0; i<str.length(); i++)
str[i] = tolower(str[i]);
cout << "Lowercase string: " << str << endl;
// empty()
bool isEmpty = str.empty();
cout << "Is string empty? " << (isEmpty ? "Yes" : "No") << endl;
// front()
char frontChar = str.front();
cout << "First character: " << frontChar << endl;
// back()
char backChar = str.back();
cout << "Last character: " << backChar << endl;
// c_str()
const char* cString = str.c_str();
cout << "C-style string: " << cString << endl;
// stoi()
string numericString = "12345";
int numericValue = stoi(numericString);
cout << "Numeric value: " << numericValue << endl;
// to_string()
int intValue = 98765;
string strValue = to_string(intValue);
cout << "String value: " << strValue << endl;
// resize()
str.resize(5);
cout << "Resized string: " << str << endl;
// clear()
str.clear();
cout << "Cleared string: " << str << endl;
return 0;
} // see t.me/CPP_Coding/46
In upper 2 programs i given 20 string functions 10 10 on each
Learn it
You can also run it by clicking on run button then show button
[Comment here for anything else]
Learn it
You can also run it by clicking on run button then show button
[Comment here for anything else]
// Function declaration in c++
#include <iostream>
void greet() {
std::cout << "Hello, World!" << std::endl;
}
int main() {
greet(); // Output: Hello, World!
return 0;
}
// @CPP_Coding
#include <iostream>
void greet() {
std::cout << "Hello, World!" << std::endl;
}
int main() {
greet(); // Output: Hello, World!
return 0;
}
// @CPP_Coding
// Function with parameters and return value:
#include <iostream>
int add(int a, int b) {
return a + b;
}
int main() {
int result = add(3, 4);
std::cout << "The sum is: " << result << std::endl;
return 0;
}
// @CPP_Coding
#include <iostream>
int add(int a, int b) {
return a + b;
}
int main() {
int result = add(3, 4);
std::cout << "The sum is: " << result << std::endl;
return 0;
}
// @CPP_Coding
// Function with default parameter values:
#include <iostream>
void printMessage(std::string message = "Hello, World!") {
std::cout << message << std::endl;
}
int main() {
printMessage();
printMessage("Greetings!");
return 0;
}
// @CPP_Coding
#include <iostream>
void printMessage(std::string message = "Hello, World!") {
std::cout << message << std::endl;
}
int main() {
printMessage();
printMessage("Greetings!");
return 0;
}
// @CPP_Coding
// Function with function overloading:
#include <iostream>
int multiply(int a, int b) {
return a * b;
}
double multiply(double a, double b) {
return a * b;
}
int main() {
int result1 = multiply(3, 4);
double result2 = multiply(2.5, 1.5);
std::cout << "Result 1: " << result1 << std::endl;
std::cout << "Result 2: " << result2 << std::endl;
return 0;
} // @CPP_Coding
#include <iostream>
int multiply(int a, int b) {
return a * b;
}
double multiply(double a, double b) {
return a * b;
}
int main() {
int result1 = multiply(3, 4);
double result2 = multiply(2.5, 1.5);
std::cout << "Result 1: " << result1 << std::endl;
std::cout << "Result 2: " << result2 << std::endl;
return 0;
} // @CPP_Coding
// taking inputs by cpp
#include <iostream>
#include <string>
int main() {
std::string name;
std::cout << "Enter your first name: ";
std::cin >> name;
std::cout << "Hello, " << name << "! Nice to meet you!" << std::endl;
return 0;
}
// @CPP_Coding
#include <iostream>
#include <string>
int main() {
std::string name;
std::cout << "Enter your first name: ";
std::cin >> name;
std::cout << "Hello, " << name << "! Nice to meet you!" << std::endl;
return 0;
}
// @CPP_Coding
👍2
// taking string ( with spaces )
#include <iostream>
#include <string>
int main() {
std::string name;
std::cout << "Enter your name: ";
std::getline(std::cin, name);
std::cout << "Hello, " << name << "! Nice to meet you!" << std::endl;
return 0;
}
// @CPP_Coding
#include <iostream>
#include <string>
int main() {
std::string name;
std::cout << "Enter your name: ";
std::getline(std::cin, name);
std::cout << "Hello, " << name << "! Nice to meet you!" << std::endl;
return 0;
}
// @CPP_Coding
// Taking inputs ( integers in cpp )
#include <iostream>
#include <string>
int main() {
std::string num1, num2;
std::cout << "Enter first number: ";
std::cin >> num1;
std::cout << "Enter second number: ";
std::cin >> num2;
// Typecasting string to integer
int num1Int = std::stoi(num1);
int num2Int = std::stoi(num2);
std::cout << "Sum of numbers is " << num1Int + num2Int << std::endl;
return 0;
}
// @CPP_Coding
#include <iostream>
#include <string>
int main() {
std::string num1, num2;
std::cout << "Enter first number: ";
std::cin >> num1;
std::cout << "Enter second number: ";
std::cin >> num2;
// Typecasting string to integer
int num1Int = std::stoi(num1);
int num2Int = std::stoi(num2);
std::cout << "Sum of numbers is " << num1Int + num2Int << std::endl;
return 0;
}
// @CPP_Coding
//To check numbers Amicable or not..
//Definition of Amicable nums:👉Amicable numbers are two different positive integers such that each number is the sum of the proper divisors of the other number...😊
#include<iostream>
using namespace std;
int s_divisors (int N) {
int i,s=0;
for(i=1; i<=N/2; i++) {
if(N%i==0)
s=s+i;
}
return s;
}
int main() {
int a,b;
cout<<"Enter first number:";
cin>>a;
cout<<"Enter second number:";
cin>>b;
if((s_divisors(a)==b)&&(s_divisors(b)==a))
cout<<a<<" and "<<b<<" are Amicable✔️";
else
cout<<a<<" and "<<b<<" are Not Amicable❌";
return 0;
}
//@CPP_Coding
//Definition of Amicable nums:👉Amicable numbers are two different positive integers such that each number is the sum of the proper divisors of the other number...😊
#include<iostream>
using namespace std;
int s_divisors (int N) {
int i,s=0;
for(i=1; i<=N/2; i++) {
if(N%i==0)
s=s+i;
}
return s;
}
int main() {
int a,b;
cout<<"Enter first number:";
cin>>a;
cout<<"Enter second number:";
cin>>b;
if((s_divisors(a)==b)&&(s_divisors(b)==a))
cout<<a<<" and "<<b<<" are Amicable✔️";
else
cout<<a<<" and "<<b<<" are Not Amicable❌";
return 0;
}
//@CPP_Coding
👍3
//To find Largest word and Smallest word in a string..
#include<iostream>
#include<string.h>
using namespace std;
int main() {
char str[100]= {0},substr[100][100]= {0};
cout<<"Enter string:";
cin.getline (str, 100);
int i = 0, j = 0, k = 0, a, minIndex = 0, maxIndex = 0, max = 0, min = 0;
while (str[k] != '\0') {
j = 0;
while (str[k] != ' ' && str[k] != '\0' && str[k]!='.') {
substr[i][j] = str[k];
k++;
j++;
}
substr[i][j] = '\0';
i++;
if (str[k] != '\0') {
k++;
}
}
int len = i;
max = strlen(substr[0]);
min = strlen(substr[0]);
for (i = 0; i < len; i++) {
a = strlen(substr[i]);
if (a > max) {
max = a;
maxIndex = i;
}
if (a < min) {
min = a;
minIndex = i;
}
}
cout<<"Largest Word is:" <<substr[maxIndex]<<endl<<"Smallest word is:"<<substr[minIndex]<<endl;
return 0;
}
//@CPP_Coding
#include<iostream>
#include<string.h>
using namespace std;
int main() {
char str[100]= {0},substr[100][100]= {0};
cout<<"Enter string:";
cin.getline (str, 100);
int i = 0, j = 0, k = 0, a, minIndex = 0, maxIndex = 0, max = 0, min = 0;
while (str[k] != '\0') {
j = 0;
while (str[k] != ' ' && str[k] != '\0' && str[k]!='.') {
substr[i][j] = str[k];
k++;
j++;
}
substr[i][j] = '\0';
i++;
if (str[k] != '\0') {
k++;
}
}
int len = i;
max = strlen(substr[0]);
min = strlen(substr[0]);
for (i = 0; i < len; i++) {
a = strlen(substr[i]);
if (a > max) {
max = a;
maxIndex = i;
}
if (a < min) {
min = a;
minIndex = i;
}
}
cout<<"Largest Word is:" <<substr[maxIndex]<<endl<<"Smallest word is:"<<substr[minIndex]<<endl;
return 0;
}
//@CPP_Coding
👍1
//Convert string to Title Case🌚
#include<iostream>
using namespace std;
void titleCase(char str[]) {
int x=0;
int prevChar=' ';
while(str[x]!='\0') {
if (prevChar==' ' or prevChar=='\t' or prevChar=='\n') {
if(str[x]>='a'&& str[x]<='z')
str[x]=str[x]-32;
}
else if(str[x]>='A'&& str[x]<='Z')
str[x]=str[x]+32;
prevChar=str[x];
x++;
}
}
int main() {
char str[50];
cout<<"Enter a string:";
cin.getline(str,50);
titleCase(str);
cout<<str;
return 0;
}
//@CPP_CODES_PRO
👍2
Notes 📝 :
Telegram.me/BCA_Sem1_Notes
Telegram.me/BCA_Sem2_Notes
Telegram.me/BCA_Sem3_Notes
Telegram.me/BCA_Sem4_Notes
Telegram.me/BCA_Sem5_Notes
Telegram.me/BCA_Sem6_Notes
Code practice Channels:
Telegram.me/C_Codes_pro
Telegram.me/CPP_Codes_pro
Telegram.me/Python_Codes_pro
Telegram.me/Java_Codes_Pro
Telegram.me/Nodejs_Codes_Pro
Info channel:
Telegram.me/Btech_bca_mca
Discussion groups:
Telegram.me/bca_mca_btech
Telegram.me/bca_group_ignou
Learn coding:
Youtube.com/IgnouStudyCenter
Telegram.me/BCA_Sem1_Notes
Telegram.me/BCA_Sem2_Notes
Telegram.me/BCA_Sem3_Notes
Telegram.me/BCA_Sem4_Notes
Telegram.me/BCA_Sem5_Notes
Telegram.me/BCA_Sem6_Notes
Code practice Channels:
Telegram.me/C_Codes_pro
Telegram.me/CPP_Codes_pro
Telegram.me/Python_Codes_pro
Telegram.me/Java_Codes_Pro
Telegram.me/Nodejs_Codes_Pro
Info channel:
Telegram.me/Btech_bca_mca
Discussion groups:
Telegram.me/bca_mca_btech
Telegram.me/bca_group_ignou
Learn coding:
Youtube.com/IgnouStudyCenter
C++ Codes basic to advance pinned «Notes 📝 : Telegram.me/BCA_Sem1_Notes Telegram.me/BCA_Sem2_Notes Telegram.me/BCA_Sem3_Notes Telegram.me/BCA_Sem4_Notes Telegram.me/BCA_Sem5_Notes Telegram.me/BCA_Sem6_Notes Code practice Channels: Telegram.me/C_Codes_pro Telegram.me/CPP_Codes_pro Telegram…»
//To check leap year//@CPP_CODES_PRO
#include<iostream>
using namespace std;
int main() {
int year;
cout << "Enter a year that you want to check:";
cin>>year;
if((year%4==0 &&year%100!=0) ||( year%400==0))
cout<<year<<" is a leap year"<<endl;
else
cout<<year<<" is not a leap year"<<endl;
return 0;
}
इस बाॅट में कोड रन करना सीखें।
Learn how to run code in this bot.
See bot with Full tutorial: https://t.me/logicBots/147
लाभ (Advantage):
आप किसी को भी रियल टाइम में कोड का आउटपुट दिखा सकते हो, जिससे अगर आपके कोड में कोई गलती है तो वह भी सरलता से एक दूसरे से डिस्कस करके साॅल्व कर सकते हो।
See features written in pic ☝️☝️
You can show the output of the code to anyone in real time, so that if there is any mistake in your code, they can easily solve it by discussing with each other.
Full tutorial: https://t.me/logicBots/147
👍1