Home                        

Welcome To Programming Page Of 2k1CP

                          All the given programs are thoroughly checked & debugged and there is full guarantee for each and every program execution.

                                                             LAB # 9

Solution # 1(a)

#include<iostream.h>
#include<conio.h>
void main(void)
{
clrscr();
for(int i=10;i>=0;i--)
cout<<i<<endl;
getch();
}
 

 Solution # 1(aii)

#include<iostream.h>
#include<conio.h>
void main(void)
{
clrscr();
for(int i=10;i>=0;i--)
cout<<i<<endl;
getch();
}

Solution # 1(aiii)

#include<iostream.h>
#include<conio.h>
void main(void)
{
clrscr();
for(int i=20;i<=30;i++)
cout<<i<<endl;
getch();
}
Solution # 1(aiv)
#include<iostream.h>
#include<conio.h>
void main(void)
{
clrscr();
for(int i=1;i<=20;i+=3)
cout<<"\t"<<i;
getch();
}
Solution # 2
#include<iostream.h>
#include<conio.h>
void main(void)
{
clrscr(); long fact=1;
int f;
cout<<"Enter a number to calculate its factorial=";
cin>>f;
for(long l=f;l>0;l--)
fact=fact*l;
cout<<"Factorial of\t"<<f<<"! is"<<fact;
getch();
}
                                                                     LAB # 10

Solution # 1

#include<iostream.h>
#include<conio.h>
void main(void)
{
clrscr();
char calc;
int a,b;
cout<<"Enter two integers you want\n";
cin>>a>>b;
cout<<"\nEnter the operator you want to ckeack among +,-,/,*=";
cin>>calc;
switch(calc)
{ case'+':
cout<<a<<"+"<<b<<"="<<a+b;
break;
case'-':
cout<<a<<"-"<<b<<"="<<a-b;
break;
case'*':
cout<<a<<"*"<<b<<"="<<a*b;
break;
case'/':
cout<<a<<"/"<<b<<"="<<a/b;
default:
cout<<"wrong operator";
}
getch();
}
 

Solution # 2

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main(void)
{
clrscr();
int x=-9;
cout<<"x without fabs="<<x<<endl;
cout<<"x after fabs="<<fabs(x)<<endl;
cout<<"x after abs="<<abs(x)<<endl;
getch();
}

Solution # 3

#include<iostream.h>
#include"conio.h"
void main(void)
{
clrscr();
int i,k=1,sum=0;
cout<<"enter integer>1=";
cin>>i;
for(int j=1;j<=i;j++)
{ k=j*j;
sum+=k;}
cout<<"sum="<<sum;
getch();
}
 

Solution # 4

#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main(void)
{
clrscr();
int uppercase=0; char ch;
int lowercase=0;
int digit=0;
int space=0;
cout<<"Enter any character...\n";
cin>>ch;
while(ch!=0)
{

if(isupper(ch))
++uppercase;
break;
if(islower(ch))
++lowercase;
break;
if(isdigit(ch))
++digit;
break;
if(isspace(ch))
++space;
break;
} ch++;

cout<<"Upper case="<<uppercase<<endl;
cout<<"Lower case="<<lowercase<<endl;
cout<<"Digits="<<digit<<endl;
cout<<"Spaces="<<space<<endl;
getch();
}

 

 Solution # 5

#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main(void)
{ clrscr();
char ch,c;
cout<<"enter a character=";
cin>>ch;
c=toupper(ch);
cout<<"\nuppercase="<<c;
getch();
}

Solution # 6

#include<iostream.h>
#include<conio.h>
void main(void)
{
clrscr();
int x,cond;
cout<<"Enter the number you want to check prime or not...\n";
cin>>x;
for(int i=2;i<x;i++)
if(x%i==0)
cond=1;
if(cond==1)
cout<<"Entered number is not prime";
else
cout<<"Entered number is prime";
getch();
}
 

 

Labs from 9-10 are on this page.

          Wanna query about any program or suggestions. Mail us on : -

                        [email protected]

                     ©2001.All rights reserved by www.2k1cp.com.

               

 

 

Hosted by www.Geocities.ws

1