You are on page 1of 7

WAP to enter a string and in the string convert all the lower case to upper case and upper

case to lower case


#include<iostream.h> #include<stdio.h> #include<conio.h> #include<ctype.h> void main() { clrscr(); int i; char a[20]; cout<<"enter a string: "; gets(a); cout<<"the string entered is: "; puts(a); for(i=0;a[i]!='\0';i++) { if(isupper(a[i])) { } else if(islower(a[i])) { } } cout<<endl<<"the modified string is: "; puts(a); getch(); } a[i]=toupper(a[i]); a[i]=tolower(a[i]);

WAP to enter a string and count no. of vowels, spaces and any other character

#include<iostream.h> #include<stdio.h> #include<conio.h> void main() { clrscr(); int n=0,m=0,p=0,i; char a[20]; cout<<"enter a string: "; gets(a); cout<<endl<<"the entered string is: "; puts(a); for(i=0;a[i]!='\0';i++) { if((a[i]=='a')||(a[i]=='e')||(a[i]=='i')||(a[i]=='o')||(a[i]=='u')) { } else if(a[i]==' ') { } else { }} cout<<"No. of vowels= "<<n<<endl; cout<<"No. of spaces= "<<m<<endl; cout<<"No. of other char= "<<p<<endl; getch(); } p=p+1; m=m+1; n=n+1;

WAP to enter a string and check if it is a pallandrome or not

#include<iostream.h> #include<stdio.h> #include<conio.h> #include<string.h> void main() { clrscr(); int i,j,k; char stra[5]; cout<<"enter a string: "; gets(stra); k=strlen(stra); int flag=1; for(i=0,j=k-1;i<k;i++,j--) { if(stra[i]!= stra[j]) { flag=0; break; } } if(flag==1) { } else { } getch(); } cout<<endl<<"it is not a pallandrome"; cout<<endl<<"it is a pallandrome";

WAP to enter a 2D array and find out sum row and column wise
#include<iostream.h> #include<conio.h> void main() { clrscr(); int a[3][3],i,j,ch,s; for(i=0;i<3;i++) { for(j=0;j<3;j++) { cout<<endl<<"enter element a("<<i<<","<<j<<"): "; cin>>a[i][j]; } } cout<<endl<<"Enter Choice 1: Row Sum 2: Column Sum== "; cin>>ch; switch(ch) { case 1: for(i=0;i<3;i++) { s=0; for(j=0;j<3;j++) { } cout<<endl<<"Sum of "<<i<<" row = "<<s; } break; case 2: for(j=0;j<3;j++) { s=0; for(i=0;i<3;i++) { } cout<<endl<<"Sum of "<<j<<" Column ="<<s; s=s+a[i][j]; s=s+a[i][j];

} break; default : cout<<"error"; break; } getch(); }

WAP to enter a 2D array and find out sum of left and right diagonal
#include<iostream.h> #include<conio.h> void main() { clrscr(); int a[3][3],i,j,ch,s=0; const int size=3; for(i=0;i<3;i++) { for(j=0;j<3;j++) { cout<<endl<<"enter element a("<<i<<","<<j<<"): "; cin>>a[i][j]; } } cout<<endl<<"Enter Choice 1: left diagonal Sum 2: right diagonal Sum== "; cin>>ch; switch(ch) { case 1: for(i=0;i<3;i++) { for(j=0;j<3;j++) { if(i==j) { }}} cout<<endl<<"Sum of left diagonal= "<<s; break; case 2: for(i=0;i<3;i++) { for(j=0;j<3;j++) { if((i+j)==(size-1)) { }}} s=s+a[i][j]; s=s+a[i][j];

cout<<endl<<"Sum of right diagonal= "<<s; break; default : cout<<"error"; break; } getch(); }

You might also like