refresh d' page pag gusto nyo change ♫♪♫♪♪♪♫


Friday, February 6, 2009

CS exercises

EXERCISE 9 (CHARACTERS)

#include
#include
#include
void main()
{
clrscr();
int lenght;
char word[1000];
int charac=0,spaces=0,operators=0,special=0;

printf (" Enter the word: ");
scanf("c",&word);gets(word);
lenght=strlen(word);

for(int x=0; x {
if(word[x]>='A'&&word[x]<='Z'|| word[x]>='a'&& word[x]<='z')
{
charac++;
}
else if(word[x]==' ')
{
spaces++;
}
else if(word[x]=='+'||word[x]=='-'||word[x]=='/'||word[x]=='*')
{
operators++;
}
else
{
special++;
}
}

printf("\n\nThe Number of character is %d",charac);
printf("\n\nThe Number of Spaces is %d",spaces);
printf("\n\nThe Number of Operator is %d",operators);
printf("\n\nThe Number of Special Character %d",special);



getch();
}



OUTPUT:







EXERCISE 1

#include
#include

void main()
{

clrscr();

printf("HELLO WORLD!\n");

getch();
}


OUTPUT:




EXERCISE 2

#include
#include

void main()
{

clrscr();

printf("¯ My AutoBiography ®\n");
printf("\nIm Gerald Carlo Bauzon Tuazon, My friends call me keno and also my family and \nrelatives. I like to play basketball, computer games and more.\n");
printf("I like to eat also. I live in Davao ofcourse, at 33dau st. Monte Maria Village, davao city.\n");

getch();
}

OUTPUT:





EXERCISE 3

#include
#include

void main(){
clrscr();
int salary,years,bonus,sum;
printf("\n\tEnter employees Salary here:");
scanf("%d",&salary);

printf("\n\tEnter years:");
scanf("%d",&years);

switch(years){

case 1:
bonus=0.10*salary;
sum=salary+bonus;
printf("\n\tEmployee/s bonus is \"P%d",bonus);
printf("\n\nEmployee/s will receive a salary of \"P%d\"",sum);
break;
case 2:
bonus=0.20*salary;
sum=salary+bonus;
printf("\n\tEmployee/s bonus is \"P%d",bonus);
printf("\n\nEmployee/s will receive a salary of \"P%d\"",sum);
break;
case 3:
bonus=0.20*salary;
sum=salary+bonus;
printf("\n\tEmployee/s bonus is \"P%d",bonus);
printf("\n\nEmployee/s will receive a salary of \"P%d\"",sum);
break;
case 4:
bonus=0.10*salary;
sum=salary+bonus;
printf("\n\tEmployee/s bonus is \"P%d",bonus);
printf("\n\nEmployee/s will receive a salary of \"P%d\"",sum);
break;
case 5:
bonus=0.50*salary;
sum=salary+bonus;
printf("\n\tEmployee/s bonus is \"P%d",bonus);
printf("\n\nEmployee/s will receive a salary of \"P%d\"",sum);
break;
case 6:
bonus=0.50*salary;
sum=salary+bonus;
printf("\n\tEmployee/s bonus is \"P%d",bonus);
printf("\n\nEmployee/s will receive a salary of \"P%d\"",sum);
break;

case 7:
bonus=0.50*salary;
sum=salary+bonus;
printf("\n\tEmployee/s bonus is \"P%d",bonus);
printf("\n\nEmployee/s will receive a salary of \"P%d\"",sum);
break;
case 8:
bonus=0.50*salary;
sum=salary+bonus;
printf("\n\tEmployee/s bonus is \"P%d",bonus);
printf("\n\nEmployee/s will receive a salary of \"P%d\"",sum);
break;
case 9:
bonus=0.50*salary;
sum=salary+bonus;
printf("\n\tEmployee/s bonus is \"P%d",bonus);
printf("\n\nEmployee/s will receive a salary of \"P%d\"",sum);
break;

case 10:
bonus=0.50*salary;
sum=salary+bonus;
printf("\n\tEmployee/s bonus is \"P%d",bonus);
printf("\n\nEmployee/s will receive a salary of \"P%d\"",sum);
break;
}
if(years>=11)
{
bonus=0.75*salary;
sum=salary+bonus;
printf("\n\tEmployee/s bonus is \"P%d",bonus);
printf("\n\nEmployee/s will receive a salary of \"P%d\"",sum);
}
printf("\n\n\t\t\" BALATO HA?! HEHEHE\"");

getch();
}

OUTPUT:




EXERCISE 4

#include
#include
#include

void main(){
clrscr();
int h,i,j,x,y,choice,X;

printf("\nEnter your favorite number:");
scanf("%d",&h);
printf("\nSelect pattern you like to appear!");
printf("\n\t[A] for Pattern 1");
printf("\n\t[B] for Pattern 2");
printf("\n\t[C] for Pattern 3");
printf("\n\t[D] for Pattern 4");
printf("\nEnter your choice Pattern here:");
scanf("%s",&choice);
switch(choice)
{
case 'A':
for(i=1,y=10;i<=h;i++,y++) { for(j=1,x=35;j<=i;j++,x++) { gotoxy(x,y); printf("*"); } } break; } switch(choice) { case 'B': for(i=1,y=10;i<=h;i++,y++) { for(j=1,x=35;j<=i;j++,x--) { gotoxy(x,y); printf("*"); } } break; } switch(choice) { case 'C': for(i=h,y=10;i<=h;i--,y++) { for(j=i,x=35;j>=1;j--,x++)
{
gotoxy(x,y);
printf("*");
}
}
break;
}
switch(choice)
{
case 'D':
for(i=h,y=10;i>=1;i--,y++)
{
for(j=i,x=35;j>=1;j--,x--)
{
gotoxy(x,y);
printf("*");
}
}
break;
}
printf("\n\nSo, you got a nice pattern. Well. (--,)\n\nBY:\n ¯ ca r L o ");
getch();
}

OUTPUT:







EXERCISE 5

#include
#include


void main(){
clrscr();
int choice,a,b,n,y,sum=0,sub=0,mul=0,div=0;

gotoxy(30,4);textcolor(BLUE+BLINK);cprintf("W E L C O M E");
gotoxy(26,6);textcolor(CYAN);cprintf("\nSelect operation you like to:");
gotoxy(25,8);textcolor(GREEN);cprintf("\n\t¯ A ® ADDITION");
gotoxy(25,9);textcolor(GREEN);cprintf("\n\t¯ B ® SUBTRACTION");
gotoxy(25,10);textcolor(GREEN);cprintf("\n\t¯ C ® MULTIPLICATION");
gotoxy(25,11);textcolor(GREEN);cprintf("\n\t¯ D ® DIVISION");
gotoxy(25,12);textcolor(YELLOW);cprintf("\n\t[E] for Exit");
gotoxy(25,14);textcolor(CYAN);cprintf("\nChoose from above:");
scanf("%s",&choice);
switch(choice)
{
case 'A':
gotoxy(25,16);textcolor(YELLOW);cprintf("Enter number:");
scanf("%d",&a);
gotoxy(25,17);textcolor(YELLOW);cprintf("Enter a number again:");
scanf("%d",&b);
sum=a+b;
gotoxy(25,18);textcolor(YELLOW);cprintf("Sum of two numbe is: %d",sum);
gotoxy(25,19);textcolor(RED+BLINK);cprintf("good job idoL! (--,)");
break;
}
switch(choice)
{
case 'B':
gotoxy(25,16);textcolor(YELLOW);cprintf("Enter number:");
scanf("%d",&a);
gotoxy(25,17);textcolor(YELLOW);cprintf("Enter a number again:");
scanf("%d",&b);
sub=a-b;
gotoxy(25,18);textcolor(YELLOW);cprintf("Sub of two number is: %d",sub);
gotoxy(25,19);textcolor(RED+BLINK);cprintf("good job idoL!");
break;
}
switch(choice)
{
case 'C':
gotoxy(25,16);textcolor(YELLOW);cprintf("Enter number:");
scanf("%d",&a);
gotoxy(25,17);textcolor(YELLOW);cprintf("Enter a number again:");
scanf("%d",&b);
mul=a*b;
gotoxy(25,18);textcolor(YELLOW);cprintf("Mul of two numbe is: %d",mul);
gotoxy(25,19);textcolor(RED+BLINK);cprintf("good job idoL! (--,)");
break;
}
switch(choice)
{
case 'D':
gotoxy(25,16);textcolor(YELLOW);cprintf("Enter number:");
scanf("%d",&a);
gotoxy(25,17);textcolor(YELLOW);cprintf("Enter a number again:");
scanf("%d",&b);
div=a/b;
gotoxy(25,18);textcolor(YELLOW);cprintf("Div of two number is: %d",div);
gotoxy(25,19);textcolor(RED+BLINK);cprintf("good job idoL! (--,)");
break;
}
switch(choice)
{
case'E':
gotoxy(25,18);textcolor(LIGHTCYAN+BLINK);cprintf("\n\nIts the END of it, take care!");
}
getch();
}

OUTPUT:








EXERCISE 7

#include
#include
#include
void menu();
void nextscreen();
void nextscreen2();
void nextscreen()
{
clrscr();
int x,y,z;
for(x=1;x<=77;x++) { gotoxy(2+x,1);textcolor(WHITE);cprintf("Í"); gotoxy(2+x,21);textcolor(WHITE);cprintf("Í"); } for(y=1;y<=20;y++) { gotoxy(3,1+y);textcolor(WHITE);cprintf("º"); gotoxy(79,1+y);textcolor(WHITE);cprintf("º"); } gotoxy(3,1);textcolor(WHITE);cprintf("É"); gotoxy(3,21);textcolor(WHITE);cprintf("È"); gotoxy(79,1);textcolor(WHITE);cprintf("»"); gotoxy(79,21);textcolor(WHITE);cprintf("¼"); } void menu() { nextscreen(); nextscreen2(); int choice,a,b,n,y,sum=0,sub=0,mul=0,div=0,z; gotoxy(30,2);textcolor(CYAN);cprintf("E X E R C I S E 7"); gotoxy(30,5);textcolor(CYAN);cprintf("W E L C O M E ! ! !"); gotoxy(26,6);textcolor(CYAN);cprintf("\nSelect operation you like to Try!"); gotoxy(25,8);textcolor(CYAN);cprintf("\n\t[A] for ADDITION"); gotoxy(25,9);textcolor(CYAN);cprintf("\n\t[B] for SUBTRACTION"); gotoxy(25,10);textcolor(CYAN);cprintf("\n\t[C] for MULTIPLICATION"); gotoxy(25,11);textcolor(CYAN);cprintf("\n\t[D] for DIVISION"); gotoxy(25,12);textcolor(CYAN);cprintf("\n\t[E] for Exit"); gotoxy(25,14);textcolor(CYAN);cprintf("\nEnter your choice operation here:"); scanf("%s",&choice); switch(choice) { case 'A': clrscr(); nextscreen(); nextscreen2(); gotoxy(25,5);textcolor(CYAN);cprintf("A] A D D I T I O N"); gotoxy(25,6);textcolor(RED);cprintf("Enter number:"); scanf("%d",&a); gotoxy(25,8);textcolor(LIGHTCYAN);cprintf("Enter another number:"); scanf("%d",&b); sum=a+b; gotoxy(25,10);textcolor(RED);cprintf("Sum of two number is: %d",sum); gotoxy(25,12);textcolor(LIGHTCYAN);cprintf("G O O D ! ! !\n"); gotoxy(25,14);textcolor(RED);cprintf("Go mainmenu [y/n]?"); scanf("%s",&z); menu(); getch(); break; } switch(choice) { case 'B': clrscr(); nextscreen(); nextscreen2(); gotoxy(25,5);textcolor(CYAN);cprintf("B] S U B T R A C T I O N"); gotoxy(25,6);textcolor(RED);cprintf("Enter number:"); scanf("%d",&a); gotoxy(25,8);textcolor(LIGHTCYAN);cprintf("Enter another number:"); scanf("%d",&b); sub=a-b; gotoxy(25,10);textcolor(LIGHTCYAN);cprintf("Subtraction of two number is: %d",sub); gotoxy(25,12);textcolor(CYAN);cprintf("G O O D ! ! ! "); gotoxy(25,14);textcolor(LIGHTCYAN);cprintf("Go to mainmenu [y/n]?"); scanf("%s",&z); menu(); getch(); break; } switch(choice) { case 'C': clrscr(); nextscreen(); nextscreen2(); gotoxy(25,5);textcolor(CYAN);cprintf("C] M U L T I P L I C A T I O N"); gotoxy(25,6);textcolor(RED);cprintf("Enter number:"); scanf("%d",&a); gotoxy(25,8);textcolor(LIGHTCYAN);cprintf("Enter another number:"); scanf("%d",&b); mul=a*b; gotoxy(25,10);textcolor(CYAN);cprintf("Muliplication of two number is: %d",mul); gotoxy(25,12);textcolor(LIGHTCYAN);cprintf("G O O D ! ! ! !"); gotoxy(25,14);textcolor(GREEN);cprintf("Go to mainmenu [y/n]?"); scanf("%s",&z); menu(); getch(); break; } switch(choice) { case 'D': clrscr(); nextscreen(); nextscreen2(); gotoxy(25,5);textcolor(CYAN);cprintf("D] D I V I S I O N"); gotoxy(25,6);textcolor(RED);cprintf("Enter number:"); scanf("%d",&a); gotoxy(25,8);textcolor(LIGHTCYAN);cprintf("Enter another number:"); scanf("%d",&b); div=a/b; gotoxy(25,10);textcolor(CYAN);cprintf("Division of two number is: %d",div); gotoxy(25,12);textcolor(LIGHTCYAN);cprintf("G O O D ! ! ! !"); gotoxy(25,14);textcolor(CYAN);cprintf("Go to mainmenu [y/n]?"); scanf("%s",&z); menu(); getch(); break; } } void nextscreen2() { clrscr(); int a,b,x,y,z; for(x=1;x<=77;x++) { gotoxy(2+x,1);textcolor(WHITE);cprintf("Í"); gotoxy(2+x,21);textcolor(WHITE);cprintf("Í"); } for(y=1;y<=20;y++){ gotoxy(3,1+y);textcolor(WHITE);cprintf("°"); gotoxy(79,1+y);textcolor(WHITE);cprintf("°"); } gotoxy(3,1);textcolor(WHITE);cprintf("É"); gotoxy(3,21);textcolor(WHITE);cprintf("È"); gotoxy(79,1);textcolor(WHITE);cprintf("»"); gotoxy(79,21);textcolor(WHITE);cprintf("¼"); for(a=1;a<=49;a++) { gotoxy(15+a,4);textcolor(WHITE);cprintf("°"); gotoxy(15+a,17);textcolor(WHITE);cprintf("°"); } for(b=1;b<=14;b++) { gotoxy(16,3+b);textcolor(WHITE);cprintf("°"); gotoxy(65,3+b);textcolor(WHITE);cprintf("° "); } } void main() { clrscr(); nextscreen(); nextscreen2(); menu(); getch(); } OUTPUT:











EXERCISE 8

#include
#include


void main()
{
clrscr();
float sum,grade,average;
int a=0;
gotoxy(17,3);textcolor(CYAN);cprintf("G R A D I N G S Y S T E M\n");
while(grade!=-1)
{sum=sum+grade;
printf("\nEnter grade;-1 to exit:");
scanf("%f",&grade);

if(grade==-1)
{printf("\nAverage is %.2f\n",average=sum/a);}
a++;
}
if(average>=95 && average<=100.00){ textcolor(YELLOW);cprintf("\n\nRate of this average: A");} else if(average>=90 && average<=94.99){ textcolor(YELLOW);cprintf("\n\nRate of this average: B");} else if(average>=85 && average<=89.99){ textcolor(YELLOW);cprintf("\n\nRate of this average: C");} else if(average>=80 && average<=84.99){ textcolor(YELLOW);cprintf("\n\nRate of this average: D");} else if(average>=75 && average<=79.99){ textcolor(YELLOW);cprintf("\n\nRate of this average: E");} else if(average<74){>OUTPUT: