Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Kendriya Vidyalaya Aliganj Holiday Homework Class XI Computer Science Write program for the following: LE 6.1 Write a program to print number from 1 to 10. #include<iostream.h> #include<conio.h> void main() { clrscr(); int i; for(i=1;i<=10;++i) cout<<"\n"<<i; getch(); } LE 6.2 Write a program to calculate the sum of first 10 natural number. #include<iostream.h> #include<conio.h> void main() { clrscr(); int i,sum; for(i=1,sum=0;i<=10;++i) { sum=sum+i; } cout<<"\nSum of first 10 natural numbers is:\n"<<sum; getch(); } LE 6.3 Write a program to find the factorial value of any number entered through the keyboard. #include<iostream.h> #include<conio.h> void main() { clrscr(); int fact,i,n; cout<<"Enter te number: \n"; cin>>n; for(i=1,fact=1;i<=n;++i) { fact=fact*i; } cout<<"Factorial of "<<n<<" natural numbers is: "<<fact; getch(); } LE 6.4 Write a program to find the value of one number raised to the power of another. #include<iostream.h> #include<conio.h> #include<math.h> void main() { clrscr(); float a,b,c; cout<<"Enter the number and its power:"; cin>>a>>b; c=pow(a,b); cout<<"Result is:"<<c; getch(); } LE 6.5 Write a program to reveres any given POSITIVE integer number. #include<iostream.h> #include<conio.h> void main() { clrscr(); float a,b; cout<<"Enter the POSITIVE integer:"; cin>>a; b=1/a; cout<<"Reverse of the number is:"<<b; getch(); } LE 6.6 Write a program to sum of digits of given integer number. #include<iostream.h> #include<conio.h> void main() { clrscr(); int a,b,c,d,e; cout<<"Enter the number:"; cin>>a; b=a%10; c=a/10; d=c%10; e=c/10; cout<<"Sum of the digits is:"<<b+d+e; getch(); } LE 6.7 Write a program to check given number is prime or not. #include<iostream.h> #include<conio.h> void main() { clrscr(); int n, i, p=0; cout<<"Enter any positive integer :"; cin>>n; for(i=2;i<=n/2;++i) { if(n%i==0) p=1; else p=0; } if(p==0) cout<<"Prime"; else cout<<"Composite"; getch(); } LE 6.8 Write a program to calculate HCF of Two given number. #include<iostream.h> #include<conio.h> void main() { clrscr(); int a, b, i, hcf; cout<<"Enter two integers"; cin>>a>>b; for(i=1;i<=a || i<=b; ++i) { if(a%i==0 && b%i==0) hcf=i; } cout<<hcf; getch(); } LE 6.9 Write a program to enter the numbers till the user wants and at the end it should display the count of positive, negative and zeros entered. #include<iostream.h> #include<conio.h> void main() { int n, sum_p=0, sum_n=0, sum_z=0; char choice; do { cout<<"Enter number "; cin>>n; if(n>0) sum_p++; else if(n<0) sum_n++; else sum_z++; cout<<"Do you want to Continue(y/n)? "; cin>>choice; } while(choice=='y' || choice=='Y'); cout<<"Positive Number :"<<sum_p<<"\nNegative Number :"<<sum_n<<"\nZero Number :"<<sum_z; getch(); } LE 6.10 Write a program to enter the numbers till the user wants and at the end it should display the maximum and minimum number entered. #include<iostream.h> #include<conio.h> void main() { clrscr(); int a, max=0, min=0; char ch; do { cout<<"Enter number :"; cin>>a; if(a>max) max=a; if(a<min) min=a; cout<<"Do you want to continue(y/n) :"; cin>>ch; } while(ch=='y' || ch=='Y'); cout<<"Max"<<max<<"\nMin"<<min; getch(); } LE 6.11 Write a program to print out all Armstrong numbers between 1 and 500. If 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 ) #include<iostream.h> #include<conio.h> void main() { clrscr(); int i, a, b, c; for(i=1;i<=500;i++) { a=i/100; b=i/10-a*10; c=i%10; if((a*a*a)+(b*b*b)+(c*c*c)==i) cout<<i<<"\n"; } getch(); } LE 6.12 Write a program to print Fibonacci series of n terms where n is input by user: 0 1 1 2 3 5 8 13 24..... #include<iostream.h> #include<conio.h> void main() { clrscr(); float first,second,third,n; int i; first=0; second=1; cout<<"How many elements? \n"; cin>>n; cout<<"fibonacci series\n"; cout<<first<<" "<<second; for(i=2;i<n;i++) { third=first+second; cout<<" "<<third; first=second; second=third; } getch(); } LE 6.13 Write a program to calculate the sum of following series where n is input by user. 1 + 1/2 + 1/3 + 1/4 + 1/5 #include<iostream.h> #include<conio.h> void main() { clrscr(); int i,n; float sum=0; cout<<"Enter the value of n: "; cin>>n; for(i=1;i<=n;i++) sum += 1.0/i; cout<<"Sum : "<<sum; getch(); } LE 6.14 Compute the natural logarithm of 2, by adding up to n terms in The series 1 - 1/2 + 1/3 - 1/4 + 1/5 -... 1/n where n is a positive integer and input by user. #include<iostream.h> #include<conio.h> void main() { clrscr(); int i,n,sign=-1; float sum=0; cout<<"Enter the value of n "; cin>>n; for(i=1;i<=n;i++) { sign *= -1; sum += sign*1.0/i; } cout<<"log 2 : "<<sum; getch(); } LE 6.15 Write a program to find product of two non‐negative numbers x and y (Constraint: do not use the multiplication operator) #include<iostream.h> #include<conio.h> void main() { clrscr(); int x,y,p=0; cout<<"Enter the numbers:"; cin>>x>>y; while(y>0) { p=p+x; y=y-1; } cout<<"product is:"<<p<<endl; getch(); }