Lab 4
Lab 4
int main() {
cout<<"Fatima";
return 0;
Question no 2:
Write a program to print numbers from 1 to 10
#include <iostream>
int main() {
cout<<i<<endl;
return 0;
Question no 3:
Write a program to print odd numbers from 1 to 20
#include <iostream>
int main() {
for(int i=1; i<=20; i++){
if(i%2==1){
cout<<i<<endl;
return 0;
Question no 4:
Write a program to print even numbers from 50 to 70
#include <iostream>
int main() {
if(i%2==0){
cout<<i<<endl;
return 0;
Question no 5:
Ask user to enter 10 numbers. Print the sum and average of the entered numbers.
#include <iostream>
int main() {
cin>>n;
sum=sum+n;
average=sum/10;
return 0;
Question no 6:
Enter a number and display its divisors. (e.g., divisors of 15 are: 1,3,5,15)
#include <iostream>
int main() {
int n;
cin>>n;
if(n%i==0){
cout<<i<<endl;
return 0;
}
Question no 7:
Enter a number and show its factors upto a specific number. (factors of 3 are : 3,6,9,12 …. )
#include <iostream>
int main() {
int n;
cin>>n;
n=n+3;
cout<<n<<endl;
return 0;
Question no 8:
Write a program to calculate and print the sum of all multiples of 7 from 1 to 100.
#include <iostream>
int main() {
int sum=0;
if(i%7==0){
sum=sum+i;
}
return 0;
Question no 9:
Two numbers are entered through the keyboard. Write a program to find the value of one
number raised to the power of another.
#include <iostream>
int main() {
cin>>n1;
cin>>n2;
product=product*n2;
return 0;
Question no 10:
Write a program to enter a value and calculate its factorial. (e.g., 5! = 5*4*3*2*1)
#include <iostream>
int main() {
int n, product=1;
cin>>n;
product=product*i;
cout<<product<<endl;
return 0;
Question no 11:
Enter a number and tell whether it is prime or not.
#include <iostream>
int main() {
int n, count=0;
cin>>n;
if(n%i==0){
count++;
}
if(count==0){
cout<<"Prime Number";
else{
return 0;
Question no 12:
Write a program to print Fibonacci series (1 1 2 3 5 7 12 19 31 ……)
#include <iostream>
int main() {
cout<<a<<endl<<b<<endl;
sum=a+b;
a=b;
b=sum;
cout<<sum<<endl;
return 0;
}
Question 13:
Enter a 3 digit number and find whether its Armstrong number or not? If sum of cubes of digits
of three-digit 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)
#include <iostream>
int main() {
cin>>n;
r=n%10;
cube=r*r*r;
sum=sum+cube;
n=n/10;
cout<<sum;
return 0;
Question no 16:
Write a program to print out all Armstrong numbers between 100 and 500.
1.
#include <iostream>
using namespace std;
int main() {
sum=0;
n=i;
while(n>0){
r=n%10;
cube=r*r*r;
sum=sum+cube;
n=n/10;
if(sum==i){
cout<<i<<endl;
return 0;
2.
#include <iostream>
int main() {
sum=0;
n=i;
r=n%10;
cube=r*r*r;
sum=sum+cube;
n=n/10;
if(sum==i){
cout<<i<<endl;
return 0;