Anda di halaman 1dari 5

1.

WAP to swap the values of two


variables. 3. WAP to print first 10 numbers of
fibonacii series.
# include<iostream.h>
# include<conio.h> # include<iostream.h>
void main( ) # inlude<conio.h>
{ void main( )
int a,b; {
cout<<"Enter the two variables:"; int a=0,b=1,c;
cin>>a>>b; clscr( );
int c; cout<<a<<b;
c=a; for(int i=0;i<=10;i++)
a=b; {
b=c; c=a+b;
cout<<"a:"<<a; cout<<c;
cout<<"b:"<<b; a=b;
} b=c;
}
2.WAP to print weekday using switch }
case.
4.WAP to find the factorial of a
# include<iostream.h> number.
# include<conio.h>
void main( ) # include<iostream.h>
{ # include<conio.h>
int ch; void main( )
cin>>ch; { Factorial of a number!!
switch(ch) int a,b;
6! = 1, 2, 3, 4, 5, 6
{ cout<<"Enter the
case 1:{cout<<"Monday:";} number="; All the numbers less than the
break; cin>>a;
number itself and including it
case 2:{cout<<"Tuesday:";} for(f=1;a>=1;a--)
break; { also!!
case3:{cout<<"Wednesday:";} f=f*a;
break; }
case4:{cout<<"Thursday:";} cout<<f;
break; }
case5:{cout<<"Friday:";}
break;
case6:{cout<<"Saturday:";} 5. WAP to find out the largest of 3
break; numbers.
case7:{cout<<"Sunday:";}
break; # include<iostream.h>
default:{cout<<"Invalid choice:";} # include<conio.h>
} void main( )
} {
int a,b,c;lar;larg; cout<<"Not Armstrong:";
cin>>a>>b>>c; }
lar=b>a?b:a;
larg=lar>c?lar:c; 8. WAP to input 10 values into an
cout<<larg; array then print the sum.
}
# include<iostream.h>
# include<conio.h>
6. WAP to check whether an inputted void main( )
number is perfect square or not. {
int a[10],i,sum=0;
# include<iostream.h> cout<<"Enter the 10 elements:";
# include<conio.h> for(i=0;i<10;i++)
void main( ) {
{ cin>>a[i]
int n; sum=sum+a[i];
cout<<"Enter a number:"; }
cin>>n; cout<<"Sum of the elements
int s=sqrt(n); is"<<sum;
if((s*s)==n) }
cout<<"Perfect Square";
else 9. WAP to store 5 numbers in an
cout<<"Not a Perfect Square"; array and store the value of their
} squares in another array.

# include<iostream.h>
7. WAP to check whether a number is # include<conio.h>
armstrong or not void main( )
{
# include<iostream.h> int a[5][4],i,j;
# include<conio.h> for(i=0;i<5;i++)
void main( ) {
{ for(j=0;j<4;j++)
int n,d,s=0; }
cout<<"Enter a number:"; cout<<"Enter the elements:";
cin>>n; cin>>a[i][j]
int m=n; for(i=0;i<5;i++)
while(n!=0) {
{ for(j=0;j<4;j++)
d=n%10; }
s=s+(d*d*d); cout<<a[i][j];
n/=10; }
}
if(s==m) 10. WAP to input 5 numbers then find
cout<<"Armstrong:"; out the maximum and minimum
else values
Selection Sorting!

Concept to be
cout<<a[i][j]; understood!!!!
# include<iostream.h> }
# include<conio.h> }
void main( ) }
{
int a[5],s,l; 12. WAP to sort the array of 10
for(int i=0;i<5;i++) elements.
{
cout<<"Enter the elements"; # include<iostream.h>
cin>>a[i]; # include<conio.h>
s=l=a[0]; void main( )
} {
for(int i=1;i<=4;i++) int a[10],t=0,i,j;
{ for(i=0;i<10;i++)
if(a[i]>l) {
{ cout<<"Enter the value<<i+1<<"i";
l=a{i} cin>>a[i];
} }
else if(a[i]<s) for(i=0;i<10;i++)
{ {
s=a[i]; t=0;
} for(j=i;j<10;j++)
cout<<s<<l; {
} if([j]>t)
} {
t=a[j];
11. WAP to write 2D array and print }
values of all the elements. [i]=t;
}
# include<iostream.h> cout<<"Printed in desending order";
# include<conio.h> for(i=0;i<10;i++)
void main( ) {
{ cout<<"Values"<<i+1<<":"<<a[i];
int a[10][5],i,j; t=0;
for(i=0;i<10;i++) cout<<'Printed in desending order";
{ for(i=9;i>=0;i--)
for(j=0;j,5;j++) {
{ t=t+1;
cout<<"Enter the value"; cout<<"Values"<<t<<":"<<a[i];
cin>>a[i][j]; }
} }
}
for(i=0;i,10;i++) 13. WAP to find the number of vowels
{ in a string.
for(j=o;j,5;j==)
{ # include<iostream.h>
# include<string.h> }
# include<conio.h> }
void main( ) }
{
char s[80]; 15.WAP to replace every space in a
cout<<"Enter a string"; string with a hypen "_".
cin.getline(s,80); // to get a string of
length of maximum 80 charecters # include<iostream.h>
int vc=0; # include<string.h>
for(int i=0;s[i]!='\0';i++) # include<conio.h>
if(s[i]=='a'||s[i]=='A'||s[i]=='e'|| void main( )
s[i]=='E'||s[i]=='i'||s[i]=='I'||s[i]=='o'|| {
s[i]=='O'||s[i]=='u'||s[i]=='U') // char str[80];
checking for the presence of vowels cout<<"Enter the string";
vc++; // incrementation operator to cin.getline(str.80); // to get a string of
find the number of vowels(sum) length of maximum 80 charecters
cout<<vc; for(int i=0;str[i]!='\0';i++)
//vc=vc+1 {
} i(str[i]==' ') // ' ' =>Blankspace,
Cheking for blankspace
14. WAP to read the string if it is in string[i]='_'; // '_' => Hypen, convert
lowercase convert to uppercase if it blankspace to hypen
is in uppercase them print it is cout<<"Changed string is"<<str[i];
already in uppercase. }
}
# include<iostream.h>
# include<string.h> 16. WAP to read a password and print
# include<conio.h> Ok if the password is correct
void main( ) otherwise Sorry. Only three chances
{ are given to the user.
char str[25];
cout<<"Enter the string"; # include<iostream.h>
cin.getline(str,25); # include<string.h>
for(int i=0;str[i]!='\0;i++) # include<conio.h>
{ void main( )
if(isupper(str[i])) //isupper=> to {
check whether in uppercase or not char Pass[50];
{ cout<<"Enter the password";
cout<<"Already in uppercase" cin.getline(Pass,50); // to get string
} of maximum length of 50 charecters
else if(islower(str[i]) //islower=> to for(int i=0;i<3;i++)
check whether in lowercase or not {
{ if(strcmp(Pass,"SAI")!=0)
str[i]=toupper(str[i]); // to convert //strcmp=>String Compare
from lowercase to uppercase {
cout<<str[i]; cout<<Sorry";
}
else
cout<<"Ok";
break
}
}

Anda mungkin juga menyukai