Find sum of digits of a number. Say N = 3467, Output = 3 + 4 + 6 + 7 = 20
Pseducode to print all prime numbers in the range 1 to N.
Write a program to swap two numbers without using third variable.
Find sum of digits of a number. Say N = 3467, Output = 3 + 4 + 6 + 7 = 20
Pseducode to print all prime numbers in the range 1 to N.
Write a program to swap two numbers without using third variable.
These are some basic question.
I would suggest you to try it yourself first.
Q1. You just have to extract each digit using % and / . Maintain a sum variable that will store the sum of each digit. Refer this https://www.geeksforgeeks.org/program-for-sum-of-the-digits-of-a-given-number/
Q2. Refer this https://www.geeksforgeeks.org/print-all-prime-numbers-less-than-or-equal-to-n/
Q3. The idea is to get sum in one of the two given numbers. The numbers can then be swapped using the sum and subtraction from sum.
Code for Q3. (Dry run this to understand how it works)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x = 10, y = 5;
// Code to swap 'x' and 'y'
x = x + y; // x now becomes 15
y = x - y; // y becomes 10
x = x - y; // x becomes 5
cout << "After Swapping: x =" << x << ", y=" << y;
}
sir help me psuedocode I didn’t write it and I also tried it many times…
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.