CBSE Important Questions

CBSE Guess > Papers > Important Questions > Class XI > 2010 >Computer Science >Computer Science By Mr. Ravi Kiran

CBSE CLASS XI

Q.3. Write a program to find the total number of characters, lines and words in a paragraph of text. 4
a)#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main( )
{ char str[300];
int i,charcount=0,words=1,lines=1;
clrscr();
cout<<"\nEnter the Paragraph ie message: \n";
gets(str);
for(i=0;str[i]!='\0';i++)
{ charcount++;
if(str[i]==' ')
words++;
if (charcount%80==0)
lines++;
}
cout<<"\nNumber of Characters in the entered message: "<<charcount;
cout<<"\nNumber of Words in the entered messge: "<<words;
cout<<"\nNumber of Lines in the entered message: "<<lines;
getch( );
}

Q.4. Write a program to sort an array on N numbers in ascending order. Avoid duplication of elements. 3
a) #include<iostream.h>
#include<conio.h>
void main( )
{ clrscr( );
int A[20],N,i,j,temp;
cout<<”\nEnter the number of elements:”;
cin>>N;
for(i=0;i<N;i++)
cin>>A[i];
//Bubble sort technique
for(i=0;i<N;++i)
for(j=0;j<(N-1)-i ;j++)
if(A[j]>A[j+1])
{ Temp=A[j];
A[j]=A[j+1];
A[j+1]=Temp;
}
cout<<"The Elements in the array after sorting…. ";
for(i=0;i<N;i++)
cout<<A[i]<<'\t';
}

Q. 5. Write a program to find the roots of a quadratic equation. 2
a) #include<iostream.h>
#include<conio.h>
#include<math.h>
void main( )
{ clrscr( );
double d1,d2,b,a,c,d;
cout<<"\nEnter the value of b,a and c: ";
cin>>b>>a>>c;
d=(b*b-sqrt(4*a*c));
if(d==0)
cout<<"\nRoots are equal or distinct";
else if(d>=0)
cout<<"\nRoots are Real";
else
cout<<"\nRoots are complex..ie Imaginary";
d1=(-b+d)/(2*a);
d2=(b+d)/(2*a);
cout<<"\nD1: "<<d1;
cout<<"\nD2: "<<d2;
getch( );
}

Paper By Mr. Ravi Kiran
Email Id :[email protected]