Philippine State College of Aeronautics
-
Upload
keven-guanzon -
Category
Documents
-
view
218 -
download
0
description
Transcript of Philippine State College of Aeronautics
PHILIPPINE STATE COLLEGE OF AERONAUTICSINSTITUTE OF ENGINEERING AND TECHNOLOGY
VILLAMOR AIR BASE
COMP 213:C LANGUAGE PROGRAMMING PROJECTS
SUBMITTED BY:
KEVEN VINCENT P. GUANZONBS-AeE 2-2
PRELIMINARIES
PESO TO DOLLAR CONVERSION
SOURCE CODE
#include <stdio.h>
float a,c;main(){
printf("Enter the amount in dollars:");scanf("%f",&a);c=a*45.00;printf("\nThe value in peso is %f \n",c);
printf("\nKeven Vincent P. Guanzon Future Engineer :)");return 0;
}
OUTPUT:
VALUE DEPRECIATION PROGRAM
SOURCE CODE
#include <stdio.h>
float p,y, s, d;main(){
printf("Enter the purchase price of the item:");scanf("%f",&p);printf("\nEnter the life expectancy of the item:");scanf("%f",&y);printf("\nEnter the salvage value of the item:");scanf("%f",&s);d=(p-s)/y;printf("\nThe yearly depreciation rate of the item is: %2f \n", d);
printf("\nKeven Vincent P. Guanzon Future Engineer :)");return 0;
}
OUTPUT:
OPERATORS PROGRAM
SOURCE CODE
#include <stdio.h>
#include <stdio.h>int main(){int a=41,b=20, add,sub,mul,div,mod;add = a+b;sub = a-b;mul = a*b;div = a/b;mod = a%b;printf("The sum of a and b is: %d\n", add);printf("\nThe difference of a and b is: %d\n", sub);printf("\nThe product of a and b is: %d\n", mul);printf("\nThe Quotient of a and b is: %d\n", div);printf("\nThe remainder of a and b is: %d\n", mod);printf("\nKeven Vincent P. Guanzon Future Engineer :)");return 0;}
OUTPUT:
BIRTHDAY MAGIC PROGRAM
SOURCE CODE
#include <stdio.h>int a,b,l,age,temp;main(){
printf("Enter the date of your birthmonth:\n");scanf("%d", &a);printf("Enter the day of your birthdate: \n");scanf("%d", &b);printf("Enter the last 2 digits of your birthyear: \n");scanf("%d", &l);printf("I will now add 18 to your date of your birthmonth, which is ");temp=a+18;printf("%d\n", temp);printf("I will now multiply 25 to the preceding value, which is ");temp=temp*25;printf("%d\n", temp);printf("I will now subtract 333 to the preceding value, which is ");temp=temp-333;printf("%d\n", temp);printf("I will now multply 8 to the preceding value, which is ");temp=temp*8;printf("%d\n", temp);printf("I will now subtract 554 to the preceding value, which is ");temp=temp-554;printf("%d\n", temp);printf("I will now divide the preceding value by 2, which is ");temp=temp/2;printf("%d\n", temp);printf("I will now add the day of your birthdate to the preceding value, which is ");temp=temp+b;printf("%d\n", temp);printf("I will now multiply 5 to the preceding value, which is ");temp=temp*5;printf("%d\n", temp);printf("I will now add 692 to the preceding value, which is ");temp=temp+692;printf("%d\n", temp);printf("I will now multiply 20 to the preceding value, which is ");temp=temp*20;printf("%d\n", temp);printf("I will add the last 2 digits of the birthyear to the latest value, which is \n");temp=temp+l;printf("%d\n", temp);printf("I will now subtract the preceding value by 32940, which is \n");age=temp-32940;printf("\nWe have calculated your exact birthdate with magic, is this right? --> %d\n", age);return 0;
}
OUTPUT:
OUTPUT: This is your birthdate sir! HAHA
MIDTERMS
SWITCH CASE PROGRAM: GRADE VALUES
SOURCE CODE
main()
{ char z; printf("Enter grade here (Must be A, B, C, D, or F): "); scanf("%c", &z); switch( z ) { case 'a' : printf( "\nExcellent\n" );break; case 'b' : printf( "\nGood\n" ); break; case 'c' : printf( "\nOK\n" ); break; case 'd' : printf( "\nMmmmm....\n" ); break; case 'f' : printf( "\nYou must do better than this\n" ); break; default : printf( "\nWhat is your grade anyway?\n" ); break; } printf("Keven Vincent Guanzon Future Engineer!");return 0;}
OUTPUT:
IF-ELSE PROGRAM: ODD OR EVEN
SOURCE CODE
#include <stdio.h>int main(){ int num; printf("Enter a number you want to check.\n"); scanf("%d",&num); if((num%2)==0) //checking whether remainder is 0 or not. printf("%d is even.",num); else printf("%d is odd.",num); return 0;}
OUTPUT:
NUMERICAL TO WORDS CONVERSION PROGRAM
SOURCE CODE
#include<stdio.h>#include<string.h>#include<conio.h>
main(){char a[10][10]={"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE"};char b[10][10]={"ELEVEN","TWELVE","THIRTEEN","FOURTEEN","FIFTEEN","SIXTEEN","SEVENTEEN","EIGHTEEN","NINTEEN"};char c[10][10]={"TEN","TWENTY","THIRTY","FOURTY","FIFTY","SIXTY","SEVENTY","EIGHTY","NINTY"};char d[10][10] = {"THOUSAND"};char e[10][10] = {"HUNDRED "};int no,t;printf("Enter a postive number:");scanf("%d",&no);
if(no<3001) { if(no>1000) { t=no/1000; no=no%1000; printf("%s %s",a[t-1], d); } if(no>=100) { t=no/100; no=no%100; printf(" %s %s",a[t-1],e); } if(no>=10 && no<20) { t=no-10; printf(" %s",b[t-1]); } if(no>19 && no<100) { t=no/10; no=no%10; printf("%s",c[t-1]); } if(no<10) { printf(" %s",a[no-1]);
} } else printf("Enter smaller number");printf("\nKeven Vincent Guanzon Future Engineer! :)");return 0;}
OUTPUT:
CONCATENATION PROGRAM
SOURCE CODE
#include <stdio.h>
#include <string.h> main(){ char a[1000], b[1000]; printf("Enter the first string\n"); gets(a); printf("Enter the second string\n"); gets(b); strcat(a,b); printf("String obtained on concatenation is %s\n",a); printf("Keven Vincent Guanzon Future Engineer! :)"); return 0; }
OUTPUT:
FINALS
LOOPING PROGRAM: CALCULATE THE SUM OF ALL NATURAL NUMBERS OF AN INTEGER
SOURCE CODE
#include <stdio.h>int main(){ int n, count, sum=0;
printf("Enter an integer: "); scanf("%d",&n); count=1; while(count<=n) { sum+=count; ++count; } printf("Sum = %d",sum); printf("\nTherefore,Keven Guanzon is very pogi AHAHA"); return 0;
}
OUTPUT:
DISPLAYING NUMBERS
SOURCE CODE
#include<stdio.h>int n;main(){
do{printf("%d",n);n++;
}while (n<=5);Printf(“Ken Ken”);
return 0;}
OUTPUT:
FINDING THE FACTOR OF A NUMBER
SOURCE CODE
#include <stdio.h>main()
{ int n,i; printf("Enter a positive integer: "); scanf("%d",&n); printf("Factors of %d are: ", n); for(i=1;i<=n;++i) { if(n%i==0) printf("%d ",i); } printf("\nKeven Guanzon is Awesome"); return 0; }
OUTPUT:
REVERSING A NUMBER
SOURCE CODE
#include <stdio.h>int n, reverse=0, rem;
main(){ printf("Enter an integer: "); scanf("%d", &n); while(n!=0) { rem=n%10; reverse=reverse*10+rem; n/=10; } printf("Reversed Number = %d",reverse); printf("\nEngr. Keven Vincent Guanzon"); printf("\nThank you for making programming understandable sir Montaigne!"); return 0;}
OUTPUT: