Sabtu, 10 November 2012

MINI PROJEK - CGPA


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

int main()
{
int marks[10];
int counter;
int creditHour[10];
int noOfsubject;
int totalCreditHour=0;
double sumOfgradePointxCreditHour=0;
double gradePoint[10];
double Gpa;
char subjectName[10][10];
char grade[10][10];

printf("--------------------------------------------------------------------------------");
printf("\t\t\t\t\t\t\t\t\t\t\t\t\t\t*GPA & CGPA*\n");
printf("\t\t\t\t\t\t\t\t\t\t\t\t\t\t*CALCULATOR*\n\n");
printf("--------------------------------------------------------------------------------");
printf("\n\nNo of subject :\t");
scanf("%d",&noOfsubject);

for(counter=0;counter<=noOfsubject-1;counter++)
{
printf("\nSubject no %d\n",counter+1);
printf("\nSubject name :\t");
scanf("%s",&subjectName[counter]);
printf("Enter marks :\t");
scanf("%d",&marks[counter]);
printf("Enter credit hour :\t");
scanf("%d",&creditHour[counter]);

if(marks[counter]>=80 && marks[counter]<=100)
{
gradePoint[counter]=4.00;
strcpy(grade[counter],"A");
}
else if(marks[counter]>=75 && marks[counter]<=79)
{
gradePoint[counter]=3.67;
strcpy(grade[counter],"A-");
}
else if(marks[counter]>=70 && marks[counter]<=74)
{
gradePoint[counter]=3.33;
strcpy(grade[counter],"B+");
}

else if(marks[counter]>=65 && marks[counter]<=69)
{
gradePoint[counter]=3.00;
strcpy(grade[counter],"B");
}
else if(marks[counter]>=60 && marks[counter]<=64)
{
gradePoint[counter]=2.67;
strcpy(grade[counter],"B-");
}
else if(marks[counter]>=55 && marks[counter]<=59)
{
  gradePoint[counter]=2.33;
  strcpy(grade[counter],"C+");
}
else if(marks[counter]>=50 && marks[counter]<=54)
{
gradePoint[counter]=2.00;
strcpy(grade[counter],"C");
}
else if(marks[counter]>=45 && marks[counter]<=49)
{
gradePoint[counter]=1.67;
strcpy(grade[counter],"C-");
}
else if(marks[counter]>=40 && marks[counter]<=44)
{
gradePoint[counter]=1.00;
strcpy(grade[counter],"D");
}
else if(marks[counter]>=0 && marks[counter]<=39)
{
gradePoint[counter]=0.00;
strcpy(grade[counter],"F");
}
}

for(counter=0;counter<=noOfsubject-1;counter++)
{
sumOfgradePointxCreditHour=sumOfgradePointxCreditHour+gradePoint[counter]*creditHour[counter];
totalCreditHour=totalCreditHour+creditHour[counter];
Gpa=sumOfgradePointxCreditHour/totalCreditHour;
}

system("cls");
printf("--------------------------------------------------------------------------------");
printf("No.\tSubject name\tMarks\tGrade Point  Grade\tCredithour\n");
printf("--------------------------------------------------------------------------------");

for(counter=0;counter<=noOfsubject-1;counter++)
{
printf("\n%d.\t%s\t\t%d\t %.2f\t\t%s\t%d\n",counter+1,subjectName[counter],marks[counter],gradePoint[counter],grade[counter],creditHour[counter]);
printf("\n----------------------------------------------------------------------------\n");
}

printf("\n\nthe GPA is %.2f\n",Gpa);
printf("\n");
printf("\n");
printf("\n");
printf("*THANK YOU FOR USING THIS CALCULATOR*\n");
getchar ();
}

1st Try


#include<stdio.h>

int main()
{
      printf("Selamat datang\n");
      printf("Terima kasih\n");  
      printf("jumpa lagi\n");
      getchar ();
}

Ph Value



#include<stdio.h>
int main(int)
{

int value;

printf("Please enter your pH value : ?\n");
scanf("%d", &value);
//================================================
if (value <=2)
{
          printf("very acidic");
}
//================================================
else if (value <=6)
{
     printf("acidic");
}

//================================================
else if (value == 7)
{
       printf("neutral");
}
//================================================
else if (value <12)
{
     printf("alkaline");
}
//=================================================
else
{
     printf("very alkaline");
}


scanf("%d", &value);
}

1st Class


#include<stdio.h>

int main()
{
               
                // printf("****************************************************"\n);
               
                 printf("Siti Aminah Binti Mustaffa");
               
                // Printf("04-09-2012");
               
                 printf("The best progremmer????");
               
                 printf("***************************************************\n");
                 getchar ();              
}

LATIHAN FUNCTION



void displayName(void);
void displayGroup(void);
void displayPhoneNo(void);

#include<stdio.h>
int main()
{
displayName();
displayGroup();
displayPhoneNo();
}

void displayName(void)
{
printf("Siti Aminah Binti Mustaffa\n");
}

void displayGroup(void)
{
printf("L06\n");
}

void displayPhoneNo(void)
{
printf("0136835946\n");
getchar();
}

LATUHAN GPA


#include <stdio.h>


int main(void)
{
int counter;
int creditHour[10];
int jumlahSubject;
float gradePoint[10];
float sumOfgradePointxCreditHour=0;
int totalCreditHour=0;
float Gpa;


printf("Masukkan jumlah subject:\n");
scanf("%d",&jumlahSubject);

for(counter=0;counter<=jumlahSubject-1;counter++)
{
printf("Masuk grade point dan Credit Hour untuk suject no %d\n",counter+1);
printf("Grade point :");
scanf("%f",&gradePoint[counter]);
printf("Credit Hour:");
scanf("%d",&creditHour[counter]);

}
for(counter=0;counter<=jumlahSubject-1;counter++)
{
sumOfgradePointxCreditHour=sumOfgradePointxCreditHour+gradePoint[counter]*creditHour[counter];
totalCreditHour=totalCreditHour+creditHour[counter];
Gpa=sumOfgradePointxCreditHour/totalCreditHour;
getchar ();

}

printf("the GPA is %.2f",Gpa);
getchar ();

}

Soalan C - MEAT



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

float price_beef(void);
float price_chic_meat(float b, float priceb);
void price_desplay ( void);
void Exit(void);
void credits(void);

void main()
{
int meat;
printf("\nWelcome To Aminah Online Market ");
printf("\n\n Do you want to buy meat?? \n or to see price of meat?? \n or getout!!?? ");

printf("\n\nMenu ");
printf("\n1 => Chicken ");
printf("\n2 => Beef ");
printf("\n3 => Price meat ");
printf("\n4 => Credits");
printf("\n5 => Exit ");

printf("\nPlease choose: ");
scanf("%d", &meat);
printf("\nPlease enter to continue!!");

if(meat==1)
{
getch();
system("cls");
price_chic_meat( 1, 1);


}

else if(meat==2)
{
getch();
system("cls");
price_beef();

}

else if(meat==3)
{
getch();
system("cls");
price_desplay();

}

else if(meat==5)
{
getch();
printf("\n\n");


}
else if(meat==4)
{
getch();
system("cls");
credits();

}

else
{
printf("\nOut of choice");
printf("\nPlease enter to return");
getch();
system("cls");
main();
}

}

float price_beef(void)
{
float a, pricea;
printf("\nPlease insert no of kilograms of beef that you want buy: ");
scanf("%f", &a);
pricea = a * 9.2;

printf("The price of %.2f kilogram of beef is Rm %.2f ", a, pricea);

getch();
system("cls");
main();


}

float price_chic_meat(float b, float priceb)
{

printf("\nPlease insert no of kilograms of chicken that you want buy: ");
scanf("%f", &b);
priceb = b * 6.5;

printf("The price of %.2f kilogram of chicken is Rm %.2f ", b, priceb);

getch();
system("cls");
main();


}

void price_desplay(void)
{
printf("\nChicken = Rm 6.50 per kilo");
printf("\nBeef = Rm 9.20 per kilo");
getch();
system("cls");
main();

}

void credits(void)
{
printf("\nSiti Aminah Binti Mustaffa");
printf("\n51116212268");
getch();
system("cls");
main();


}

POWER


#include<stdio.h>
int power(int a, int b);
int main(void)
{

int a, b;
printf("welcome to the power calculator\n");
printf("\n");
printf("\n enter the power of a:");
scanf("%d", &a);
printf("\n enter the base:");
scanf("%d", &b);

power(a,b);


        getchar();
return 0;


}

int power(int a, int b)
{
int power;
power = a / b;
printf("\nthe power is %d ", power);
printf("\n");
getchar();

}

XXX


#include <stdio.h>

void xxx(void);
void tolak (int);

main (void)

{
int a;
a=10;

xxx();
tolak (a);
return 0;
}

void xxx (void)
{
int a, b , c ;
a=2;
b=2;
c= 2*2;
printf("total a+b = %d\n" , c);
}

void tolak (int a)
{
int c;
c= a-3;
printf("total a-3 = %d\n",c);
getchar();
}

Khamis, 8 November 2012

FUNCTION

#include<stdio.h>

//1st type
void minus (void);//1 step
void add (void);
void main(void)
{
    //int a,b, total;
    //a=10;
   // b=20;
    minus ();//call
    printf("hello\n");
add ();
printf("hello\n");
    //printf("total sum of A+B is: %d\n",total);
}
void minus(void)
{
int a,b,total;
a=10;
b=20;
total = b-a;
printf("total sum of b-a is: %d\n",total);
}
void add (void)
{
int a,b,total;
a=10;
b=20;
total = a+b;
printf("total sum of a+b is: %d\n",total);
}

ARGENTINA


#include <stdio.h>

void argentina (void);
main ()
{
 argentina ();
 

}

void argentina (void)
{
 int a,b,c;
 a=1;
 b=2;
 c=a*b;
 printf("total a*b=%d",c); 
   

}

LOOP

#include<stdio.h>
void main(void )
{
  int i ;
  for ( i = 7 ; i <= 400 ; i=i+7)
printf ( "%d\n", i ) ;
}

CASE

#include <stdio.h>
void main(void)
{
int i = 3 ;

printf("please input i:");
scanf("%d", &i);

switch ( i )
{
case 1 :
printf ( "I am in case 1 \n" ) ;
break ;
case 2 :
printf ( "I am in case 2 \n" ) ;
break ;
case 3 :
printf ( "I am in case 3 \n" ) ;
break ;
default :
printf ( "I am in default \n" ) ;
}
}

SWITCH CASE (AREA)

//example of switch case
#include<stdio.h>
void main (void)
{

int select;
float pi,r,area,w,h,b,a,radians;
pi = 3.142;

printf("*********programs to calculate area rectangle**************\n");
printf("*                please select an option                  *\n");
printf("*                                                         *\n");
printf("*                     1.Triangular                        *\n");
printf("*                     2.Circle                            *\n");
printf("*                     3.Square                            *\n");
printf("*                     4.Ellipse                           *\n");
printf("*                     5.Trapezoid                         *\n");
printf("*                     6.Sector                            *\n");
printf("*                     7.Exit                              *\n");
printf("***********************************************************\n");

scanf("\n%d",&select);
start:// for reboot


   switch(select)
   {
      case 1:
      printf("calculate the area of triangular\n");
  //printf("calculate the area of triangular");
      printf("key in the base for calculation = ");
  scanf("\n%f",&b);
  printf("key in the height for calculation = ");
  scanf("\n%f",&h);
  area = 0.5*(b*h);
  goto answer;
  break;

  case 2:
      printf("program to calculate circle\n");
      printf("key in the radius for calculation = ");
  scanf("\n%f",&r);
  area = pi*(r*r);
  goto answer;
  break;

  case 3:
      printf("program to calculate square\n");
      printf("key in the length of side for calculation = ");
  scanf("\n%f",&a);
  area = a*a;
  goto answer;
  break;

  case 4:
      printf("program to calculate ellipse\n");
      printf("key in the length of side for calculation = ");
  scanf("\n%f",&a);
  printf("key in the base for calculation = ");
  scanf("\n%f",&b);
  area = pi*a*b;
  goto answer;
  break;

  case 5:
      printf("program to calculate trapezoid\n");
      printf("key in the length of side for calculation = ");
  scanf("\n%f",&a);
  printf("key in the base for calculation = ");
  scanf("\n%f",&b);
  printf("key in the height for calculation = ");
  scanf("\n%f",&h);
  area = 0.5*(a+b)*h;
  goto answer;
  break;

  case 6:
      printf("program to calculate sector\n");
      printf("key in the radius for calculation = ");
  scanf("\n%f",&r);
  printf("key in the angle in radians for calculation = ");
  scanf("\n%f",&radians);
  area = 0.5*(r*r)*radians;
  goto answer;
  break;

  case 7:
  goto exit;
  break;

      default:
      printf("wrong case selected!!!");
  goto exit;
   }

answer:printf("the area is = %f\n",area);
goto start;
exit:;
}

SWITCH CASE (FOOTBALL)

#include <stdio.h>
void main(void)
{
int goals ;
printf ( "Enter the number of goals scored against Indon :" ) ;
scanf ( "%d", &goals ) ;
if ( goals <= 5 )
goto sos ;
else
{
printf ( "About time soccer players learnt C\n" ) ;
printf ( "and said goodbye! adieu! to soccer \n" ) ;
return ; /* terminates program execution */
}
sos :
printf ( "To err is human!" ) ;
}

GENDER

#include<stdio.h>

void main()

{
  char gender;

  printf("Please enter your gender M or F = ");
  scanf("\n%c",&gender);

  if(gender =='M')
  {
   printf("you are %c male!!\n",gender);
  }

  else if(gender =='F')
  {
   printf("you are %c female!!\n",gender);
  }

  else
  {
printf("you dont read carefully..ish3!!\n",gender);
  }
  scanf("\n%c",&gender);
}