Take 10 integers from keyboard using loop and print their average value on the screen.
#include<iostream>usingnamespacestd;intmain(){intsum=0;for(inti=0;i<10;i++){intx;cout<<"Enter a number\n";cin>>x;sum=sum+x;}cout<<"The average value is "<<sum/10.0<<"\n";return0;}
3.
Print the following patterns using loop : a. * ** *** **** b. * *** ***** *** * c. 1010101 10101 101 1
Factorial of any number n is represented by n! and is equal to 1*2*3*....*(n-1)*n. E.g.- 4! = 1*2*3*4 = 24 3! = 3*2*1 = 6 2! = 2*1 = 2 Also, 1! = 1 0! = 0 Write a C++ program to calculate factorial of a number.
Write a program to find greatest common divisor (GCD) or highest common factor (HCF) of given two numbers.
#include<iostream>usingnamespacestd;intmain(){intx,y,gcd,lcm,t,b,a;cout<<"Enter two integers\n";cin>>x;cin>>y;a=x;b=y;while(b!=0){t=b;b=a%b;a=t;}gcd=a;lcm=(x*y)/gcd;cout<<"GCD is "<<gcd<<" and LCM is "<<lcm<<"\n";return0;}
7.
Take integer inputs from user until he/she presses q ( Ask to press q to quit after every integer input ). Print average and product of all numbers.
8.
Write an infinite loop. A inifinte loop never ends. Condition is always true.
Level 2
1.
Take as input a fraction in the form a/b. Convert the same into lowest terms and print.
(Lowest terms examples 3/12 = 1/4).
2.
Calculate the sum of digits of a number given by user. E.g.- INUPT : 123 OUPUT : 6 INUPT : 12345 OUPUT : 15
3.
A three digit number is called Armstrong number if sum of cube of its digit is equal to number itself. E.g.- 153 is an Armstrong number because (13)+(53)+(33) = 153. Write all Armstrong numbers between 100 to 500.
Write a program to print all prime number in between 1 to 100.
5.
Write a program to find prime factor of a number. If a factor of a number is prime number then it is its prime factor.
#include<iostream>usingnamespacestd;intmain(){intx;cout<<"Enter the number\n";cin>>x;cout<<"Prime factors of "<<x<<" are:\n";for(inti=2;i<=x;i++){//checking for factorif(x%i==0){//checking if i is prime or notintp=0;for(intj=2;j<i;j++){if(i%j==0){//i is not primep++;break;}}if(p==0){//if p is 0//then i is primecout<<i<<"\n";}}}return0;}
6.
Write a program to find the sum of the even and odd digits of the number which is given as input.