Thursday, February 3, 2011

Immigration from C to java[to be finished]
















In CIn java

main(){
/*Code here*/
}

public static void main(String[] args) {
/*Code here*/
}

int num;
printf("Enter a number: ");
scanf("%d",&num);

Scanner scn=new Scanner(System.in);
System.out.print("Enter a number to a variable: ");
int num=scn.nextInt();
//end of solution 1

//Start of solution 2
int num;
Scanner scn=new Scanner(System.in);
System.out.print("Enter a number to a variable: ");
num=scn.nextInt();

int x=0;
printf("x+1= %d\n",x+1);

int x=0;
System.out.println("x+1= "+(x+1));

char word[10];
printf("Enter a word: ");
scanf("%s",word);
String word;
System.out.print("Enter a word: ");
word=scn.next();
//scn is a defined scanner object from the code above

int ArrInt[5];
int[] ArrInt=new int[5]

Sunday, January 2, 2011

Happy new year

Its a new year 2011. Hope it for a prosperous and good year. The challenges will come but it can be beaten. My academic life needs improvement. I will turn 18 this year. Oh boy this could be problematic. I think I can apply ads this year so hope to earn money on my own also.

Sunday, November 28, 2010

Dealing with link list in C

Link lit in c is a challenging lesson but I am grateful that I learned it.
it was such a practical lesson. Though I still prefer to program arrays, I still find dynamic memory allocation handy. I have learned techniques that are handy.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_C 200
typedef char string7[8];
typedef char string25[26];

typedef struct
{
string25 first, last;
char mid;
}nameType;

struct courseTag
{
string7 courseCode;
float units, grade;
nameType facultyName;
};
typedef struct courseTag arrCourses[MAX_C];

struct studentTag
{
nameType name;
arrCourses course;
int numCourse;
float CGPA;
struct studentTag *pLink;
};
typedef struct studentTag *ptrStudent; /*this alias can be used to avoid confusion in using an asterisk*/
/*you can not use the same typedef call like nameType in studentTag, because you will be calling the alias that hasn't been declared yet*/

/*This function allows to insert node in alphabetical order*/
void insert(ptrStudent *pFirst){/*Alphabtical insertion*/
char tmp;
ptrStudent pNew,pRun,pLast;
pNew=malloc(sizeof(struct studentTag));
printf("Enter first name: ");
fgets(pNew->name.first,sizeof(string25),stdin);
printf("Enter miidle intial: ");
scanf("%c%c",&pNew->name.mid,&tmp);
printf("Enter last name: ");
fgets(pNew->name.last,sizeof(string25),stdin);
pNew->pLink=NULL;
if(*pFirst==NULL)
*pFirst=pNew;
else
if(strcmp((*pFirst)->name.last,pNew->name.last)>0)
{
pNew->pLink=*pFirst;
*pFirst=pNew;
}
else {
pRun=*pFirst;
while(pRun!=NULL&&strcmp(pRun->name.last,pNew->name.last)<0)
{
pLast=pRun;
pRun=pRun->pLink;
}
if(pRun)
pNew->pLink=pRun;
pLast->pLink=pNew;

}

}

Wednesday, November 10, 2010

Team trouble

Currently, we are suppose to be working on are term paper and presentation of it.
Somehow it seems that it can't be done since we have not even researched and do other important task for it. Unfortunately my schedule conflicts and their schedules are different from mine.

We need to be organized. I need a good grade in the report and presentation. I hope this won't end bad. My studies are important. My subjects are conflicting with me. I hope I get it together and so can the others

Friday, November 5, 2010

I realized form C programming

I have been studying c programming for the past months and I am in a good pace but I wish I can learn faster. It takes a month for me to learn the c language. It takes even longer to improve it. My skills improve with practice practice practice. I have no plans on stopping because I like doing it. I have passion for programming which is why I pursue learning it. I plan to learn other languages now.#

I am interested in object oriented programming. I saw this site http://www.programmersheaven.com/2/VB-NET-School and I learned Vb at a nice pace. I still want to learn more though. I plan to learn windows forms. I also want to learn c++

The other platform is java. I learned some basic java (luckily it is similar to c). Net beans helped a lot. I plan to learn more about it some other time.

I realized that it is effective to learn one platform at a time to save me from more confusion. I have confirmed that having passion on subjects you're passionate about can really makes effective learning.

I wish what I learn can help me in the future.

Wednesday, August 25, 2010

c program that displays the largest & smallest digit

================================

Displaying Largest digit from the user's input


================================

int large(int n){
if(n==0)
return 0;
else{
if(n%10>large(n/10))
return n%10;
else
return large(n/10);
}
}
int main(){
int n,ans;
printf("Enter a value: ");
scanf("%d",&n);
ans=large(n);
printf("ans: %d",ans);
getch();
}
=====================================

Displaying the smallest digit from the user's input


=====================================

int small(int n){
if(n/10==0)
return n;
else{
if(n%10
return n%10;
else
return small(n/10);
}
}
int main(){
int n,ans;
printf("Enter a value: ");
scanf("%d",&n);
ans=small(n);
printf("ans: %d",ans);
getch();
}
================================

Friday, July 23, 2010

C program that adds the digits of whole numbers

------------------------------------
#include
int main() {
int in,temp,sum=0;
printf("Enter a value: ");scanf("%d",&in);
while(in!=0){
temp=in%10;
sum+=temp;
in/=10;
}
printf("%d\n",sum);
getch();
}
------------------------------------
input <123>
the output would be<6>

Monday, July 19, 2010

Program that adds 2 sets of time info

This program adds two sets of time information in days,hours and minutes


-----------------------------------------------------------
#include
void TimeAdd(int nday,int nhrs,int nmin,int aday,int ahrs,int amin){
int carryh=0,carryd=0;
nmin+=amin;
if (nmin>=60){
carryh++;
nmin-=60;
}
nhrs+=+ahrs+carryh;
if (nhrs>=24){
carryd++;
nhrs-=24;
}
nday+=aday+carryd;
printf("Total: %d days, %d hours & %d miniutes",nday,nhrs,nmin);
}
int main(){
int nday,nhrs,nmin,aday,ahrs,amin;
printf("Type first set of time information in days,hours and miniutes ");
scanf("%d%d%d",&nday,&nhrs,&nmin);
printf("Type second set of time information in days,hours and miniutes ");
scanf("%d%d%d",&aday,&ahrs,&amin);
TimeAdd(nday,nhrs,nmin,aday,ahrs,amin);
}
------------------------------------------------------------------------
It works you can copy it to notepad & compile it your self