All years which are perfectly divisible by 4 are leap years except for century years. #include <iostream> using namespace std; int main() { int year; cout << "Enter a year: "; cin >> year; if (year % 4 == 0) { if (year % 100 == 0) { if (year % 400 == 0) cout << year << " is a leap year."; else cout << year << " is not a leap year."; } else cout << year << " is a leap year."; } else cout << year << " is not a leap year."; return 0; }…
-
-
A positive integer is called an Armstrong number if the sum of cubes of individual digit is equal to that number itself. #include <iostream> using namespace std; int main() { int origNum, num, rem, sum = 0; cout << "Enter a positive three digit integer value: "; cin >> origNum; num = origNum; while(num != 0) { rem = num % 10; sum += rem * rem * rem; num /= 10; } if(sum == origNum) cout << origNum << " is an Armstrong number."; else cout << origNum << " is not an Armstrong number."; return 0; } OutPut…
-
A positive integer value which is only divisible by 1 and itself is known as prime number. #include <iostream> using namespace std; int main() { int n, i, flag=0; cout << "Enter a positive integer value: "; cin >> n; for(i = 2; i <= n / 2; ++i) { if(n % i == 0) { flag = 1; break; } } if (flag==0) cout << "This is a prime number"; else cout << "This is not a prime number"; return 0; } OutPut Enter a positive integer value: 29 This is a prime number.
-
If the original value and its reversed value is same then it will called palindrome value. #include <iostream> using namespace std; int main() { int n, num, digit, rev = 0; cout << "Enter a positive integer number: "; cin >> num; n = num; do { digit = num % 10; rev = (rev * 10) + digit; num = num / 10; } while (num != 0); cout << " The reverse of the number is: " << rev << endl; if (n == rev) cout << " The number is a palindrome."; else cout << " The…
-
In this program, the user entered one integer value and it will find reverese of that number. #include <iostream> using namespace std; int main() { int no, rev = 0, rem; cout << "Enter an integer value: "; cin >> no; while(no != 0) { rem = no%10; rev = rev*10 + rem; no /= 10; } cout << "Reversed Number = " << rev; return 0; } OutPut Enter an integer value: 31122000 Reversed number = 00022113
-
A character variable holds ASCII value means an integer number between 0 and 127 rather than that character itself in C programming. That value is known as ASCII value. #include <iostream> using namespace std; int main() { char c; cout << "Enter a character: "; cin >> c; cout << "ASCII Value of " << c << " is " << int(c); return 0; } OutPut Enter a character: A ASCII Value of A is 65
-
The size of each variable is find using sizeof operator. #include <iostream> using namespace std; int main() { cout << "Size of char: " << sizeof(char) << " byte" << endl; cout << "Size of int: " << sizeof(int) << " bytes" << endl; cout << "Size of float: " << sizeof(float) << " bytes" << endl; cout << "Size of double: " << sizeof(double) << " bytes" << endl; return 0; } OutPut Size of char: 1 byte Size of int: 4 bytes Size of float: 4 bytes Size of double: 8 bytes
-
Swap means exchange the value of two variable. There is four different method. Using Temporary Variable Without Using Temporary Variable Using Bitwise Operator Using Multiplication And Division Using Temporary Variable #include <iostream> using namespace std; int main() { int a = 31, b = 12, temp; cout << "Before swapping " << endl; cout << "a = " << a << ", b = " << b << endl; temp = a; a = b; b = temp; cout << "\nAfter swapping" << endl; cout << "a = " << a << ", b = " << b << endl;…
-
In this program,it will takeĀ two integers (divisor and dividend) and find the quotient and remainder. To compute quotient and remainder, both divisor and dividend should be integers. #include <iostream> using namespace std; int main() { int divisor, dividend, quotient, remainder; cout << "Enter dividend: "; cin >> dividend; cout << "Enter divisor: "; cin >> divisor; quotient = dividend / divisor; remainder = dividend % divisor; cout << "Quotient = " << quotient << endl; cout << "Remainder = " << remainder; return 0; } OutPut Enter dividend: 17 Enter divisor: 4 Quotient = 4 Remainder = 1
-
In this program, two integer values taken from user and then sum of this values are stored in another variavle and then print it. #include <iostream> using namespace std; int main() { int firstNo, secondNo, sumOfTwoNo; cout << "Enter two integer values: "; cin >> firstNo >> secondNo; sumOfTwoNo = firstNo + secondNo; cout << firstNo << " + " << secondNo << " = " << sumOfTwoNo; return 0; } OutPut Enter two integer values: 4 5 4 + 5 = 9