0% found this document useful (0 votes)
3 views

loops2-assignmentfinal

The document contains C++ programming assignments focused on loops, including predicting outputs for various code snippets. It also includes tasks such as calculating the sum of even digits, summing a number with its reverse, printing factorials, generating Fibonacci numbers, and identifying Armstrong numbers. The document emphasizes the importance of understanding the concepts rather than copying solutions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

loops2-assignmentfinal

The document contains C++ programming assignments focused on loops, including predicting outputs for various code snippets. It also includes tasks such as calculating the sum of even digits, summing a number with its reverse, printing factorials, generating Fibonacci numbers, and identifying Armstrong numbers. The document emphasizes the importance of understanding the concepts rather than copying solutions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

C++ Assignments | Loops-2 | Week 3

Predict the output

#include <bits/stdc++.h>
using namespace std;

int main() {
while ('1' < '2')
cout << "In while loop" << endl;
}

Predict the output

#include <bits/stdc++.h>
using namespace std;

int main( ) {
int t = 10;
while (t /= 2) {
cout << "Hello" << endl;
}
}

Predict the output

#include <bits/stdc++.h>
using namespace std;

int main( ) {
for (int x = 1; x * x <= 10; x++)
cout << "In for loop" << endl;
}
Predict the output

#include <bits/stdc++.h>
using namespace std;

int main( ) {
int x = 10, y = 0 ;
while ( x >= y ) {
x-- ;
y++ ;
cout << x << " " << y << endl ;
}
}

WAP to print the sum of all the even digits of a given number.
Sample Input : 4556

Output: 10

WAP to print the sum of a given number and its reverse.


Sample Input : 12

Sample Output : 33 [12+21]

Print the factorials of first ‘n’ numbers


Sample Input : 10
Output :

24
120

720
5040

40320
362880

3628800

Print first ‘n’ fibonacci numbers.


Sample Input : 10

Output :
1 1 2 3 5 8 13 21 34 55

Write a program to print out all Armstrong numbers between 1 and 500. If the sum of cubes of
each digit of the number is equal to the number itself, then the number is called an Armstrong
number. For example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 )

Output :

153
370

371
407

Note:- Please try to invest time doing the assignments which are necessary to build a strong
foundation. Do not directly Copy Paste using Google or ChatGPT. Please use your brain .

You might also like