Miyerkules, Disyembre 7, 2011

String.h

▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓
▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒ 
▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓
▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓ 

String.h
--string.h is the header in the C standard library for the C programming language which contains macro definitions, constants, and declarations of functions and types used not only for string handling but also various memory handling functions; the name is thus something of a misnomer.

String copy functions
•strcpy() - copies a string to another
•strncpy() - copies n characters from a string to another

SAMPLE PROGRAM #1 [strcpy()]


#include <string.h>
  #include <stdio.h>
  #include <conio.h>
  int main()
  {
  char s1[100],s2[100];
  strcpy(s1,"hello");
  printf(“%s”,s1);
  getch();
  }


SAMPLE PROGRAM #2 [strncpy()]


#include <string.h>
  #include <stdio.h>
  #include <conio.h>
  int main()
  {
  char s1[100],s2[100];
  strncpy(s1,"hello“,2);
  printf(“%s”,s1);
  getch();
  }

String concatenation
•strcat() - concatenates two strings
•strncat() - concatenates n characters from a string onto another




SAMPLE PROGRAM #3 [strcat()]

  #include <stdio.h>
  #include <string.h>
  int main ()
  {
  char str[80];
  strcpy (str,"these ");
  strcat (str,"strings ");
  strcat (str,"are ");
  strcat (str,"concatenated.");
  puts (str); //printf in string.h
  getch();
  }


String Compare
•strcmp() - compares two strings
•strncmp() - compares n characters of two strings


SAMPLE PROGRAM #4 [strcmp()]

  #include <stdio.h>
  #include <string.h>
  int main()
  {
  char s[10] = "testing", t[10];
  strcpy(t, s);
   if (strcmp(s, t)==0)
  printf("The strings are identical.\n");    else
  printf("The strings are different.\n");
  getch();
  }


Other String Functions
•strchr() - returns the first occurrence of character in a string
•strrchr() - returns the last occurrence of character in a string
•strspn() - returns the length of leading characters in a string that are contained in a specified string
•strcspn() - returns the length of leading characters in a string not contained in a specified string
 

SAMPLE PROGRAM #5 [strchr()]

  #include <stdio.h>
  #include <string.h>
  int main ()
  {
  char str[] = "This is a sample string";
  char * pch;
  printf ("Looking for the 's' character in \"%s\"...\n“,str);
  pch=strchr(str,'s');
  while (pch!=NULL)
  {
  printf ("found at %d\n",pch-str+1);           

  pch=strchr(pch+1,'s');
  }
  getch();
  }


[OUTPUT]
Looking for the 's' character in "This is a sample string"...
found at 4
found at 7
found at 11
found at 18


SAMPLE PROGRAM #6 [strrchr()]


  #include <stdio.h>
  #include <string.h>
  int main ()
  {
  char str[] = "This is a sample string";
  char * pch;
  pch=strrchr(str,'s');
  printf ("Last occurence of 's' found at %d \n",pch-str+1);
  return 0;
  }


[OUTPUT]
Last occurrence of 's' found at 18

CONTINUATION
•strpbrk () - returns first occurrence in a string of any character in another string
•strstr () - returns the first occurrence of one string in another
•strlen()  - returns length of a string
•strtok()  - returns a token from a string delimited by specified characters
•strrev() – reverses all characters except the null terminator.

SAMPLE PROGRAM #7 [strpbrk()]


  #include <stdio.h>
  #include <string.h>
  int main ()
  {
  char str[] = "This is a sample string";
  char key[] = "aeiou";
  char * pch;
  printf ("Vowels in '%s': ",str);
  pch = strpbrk (str, key);
  while (pch != NULL)
  {
  printf ("%c " , *pch);
  pch = strpbrk (pch+1,key);
  }
  printf ("\n");
  return 0;
  }


[OUTPUT]
Vowels in 'This is a sample string': i i a a e i

SAMPLE PROGRAM #8 [strstr ()]


#include <stdio.h>
#include <string.h>
int main ()
{
  char str[] ="This is a simple string";
  char * pch;
  pch = strstr (str,"simple");
  strncpy (pch,"sample",6);
  puts (str);
  return 0;
}


[OUTPUT]
This is a sample string
 

SAMPLE PROGRAM #9 [strlen()]

#include <stdio.h>
#include <string.h>
int main ()
{
  char szInput[256];
  printf ("Enter a sentence: ");
  gets (szInput);
  printf ("The sentence entered is %u characters long.\n",strlen(szInput));
  return 0;
}


[OUTPUT]
Enter sentence: just testing
The sentence entered is 12 characters long.

SAMPLE PROGRAM #10 [strtok()]


#include <stdio.h>
#include <string.h>
int main ()
{
  char str[] ="- This, a sample string.";
  char * pch;
  printf ("Splitting string \"%s\" into tokens:\n",str);
  pch = strtok (str," ,.-");
  while (pch != NULL)
  {
  printf ("%s\n",pch);
  pch = strtok (NULL, " ,.-");
   }
  return 0;
}

[OUTPUT]
Splitting string "- This, a sample string." into tokens:
This
a
sample
string

SAMPLE PROGRAM #11 [strtok()]


#include <stdio.h>
#include <string.h>
int main ()
{
  char str[] =“reverse";
  strrev(str);
  puts(str);
  return 0;
}

[OUTPUT]
esrever


▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓
▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒ 
▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓ 
▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒

Holiday picture Collection


                                                                   AC II art

Huwebes, Oktubre 13, 2011

 
          Write a program that asks the user to enter a number n and display the first n odd numbers. Example: if n=5, the first 5 odd numbers are 1, 3, 5, 7 and 9.


     #include<stdio.h>
     #include<conio.h>
     #define min printf
     #define jee scanf

     int main()
     {
         int m, j;
   
         min("Enter a number: ");
         jee("%d",&j);
   
              for (m=1;m<=j*2;m+=2)
                 {
                 min("%d\n",m);
                 }
         getch ();
         return 0;
     }
                                                                     Sample Output:


                                                                         ▌▌▌Ü ▌▌▌

Problem number 3 ( Iterative Statements )

      Write a program that asks the user to enter a number n and display the first even numbers. Example: if n=5, the first 5 even numbers are 2, 4, 6, 8 and 10.

     #include<stdio.h>
     #include<conio.h>
     #define min printf
     #define jee scanf

     int main()
     {
         int m, j;
   
         min("Enter a number: ");
         jee("%d",&j);
   
              for ( m = 0; m <= j*2; m+=2)
                  min("%d\n",m);
            
         getch ();
         return 0;
     }
                                                                       Sample Output:


                                                                        ▌▌▌Ü ▌▌▌

Problem number 11

Write a program to determine the equivalent grade of each student in a class as follows:

      a. Read in the student's name, midterm grade, minor B, and final exam ratings.
      b. Determine the final grade of the student by formula:
          final grade = 0.30 of midterm grade + 0.10 of minor B + 0.60 of final exam.
      c. Determine the equivalent grade for the numerical value obtained by the following grading marks:

                    98 - 100 = 4.00
                    95 - 97 = 3.75
                    92 - 94 = 3.50
                    89 - 91 = 3.25
                    86 - 88 = 3.00
                    83 - 85 = 2.75
                    80 - 82 = 2.50
                    77 - 79 = 2.25
                    74 - 76 = 2.00
                    71 - 73 = 1.75
                    68 - 70 = 1.50
                    64 - 67 = 1.25
                    60 - 63 = 1.00
                    below 60= 0.00 
 

     #include<stdio.h>
     #include<conio.h>
     #define min printf
     #define jee scanf

     int main()
     {
         int mg, mb, fe;
         float fg;
         char sn;
   
         min("Enter student's name: ");
         jee("%s",&sn);
         min("Enter midterm grade: ");
         jee("%d",&mg);
         min("Enter minor B: ");
         jee("%d",&mb);
         min("Enter final exam: ");
         jee("%d",&fe);
   
         fg = ( mg * .30 ) + ( mb * .10 ) + ( fe * .60 );
         min("Your final grade is %.2f or equivalent to ",fg);
   
              if( fg >= 98 && fg <= 100)
                  {
                  min("4.00");
                  }
              else
              if( fg >= 95 && fg <= 97)
                  {
                  min("3.75");
                  }
              else
              if( fg >= 92 && fg <= 94)
                  {
                  min("3.50");
                  }
              else
              if( fg >= 89 && fg <= 91)
                  {
                  min("3.25");
                  }
              else
              if( fg >= 86 && fg <= 88)
                  {
                  min("3.00");
                  }
              else
              if( fg >= 83 && fg <= 85)
                  {
                  min("2.75");
                  }
              else
              if( fg >= 80 && fg <= 82)
                  {
                  min("2.50");
                  }
              else
              if( fg >= 77 && fg <= 79)
                  {
                  min("2.25");
                  }
              else
              if( fg >= 74 && fg <= 76)
                  {
                  min("2.00");
                  }
              else
              if( fg >= 71 && fg <= 73)
                  {
                  min("1.75");
                  }
              else
              if( fg >= 68 && fg <= 70)
                  {
                  min("1.50");
                  }
              else
              if( fg >= 64 && fg <= 67)
                  {
                  min("1.25");
                  }
              else
              if( fg >= 60 && fg <= 63)
                  {
                  min("1.00");
                  }
              else
                  {
                  min("0.00");
                  }
         getch ();
         return 0;
      }
                                                                    Sample Output:
 










                                                                         ▌▌▌Ü ▌▌▌

Problem number 9

      Write a program that will display "IT'S COLD!" if the temperature is less than 20, "IT'S HOT!" if the temperature is greater than 30, "COOL CLIMATE!" otherwise.


     #include<stdio.h>
     #include<conio.h>
     #define min printf
     #define jee scanf

     int main()
     {
         int temp;
   
         min("Enter temperature: ");
         jee("%d",&temp);
   
              if ( temp < 20 )
                  {
                  min("IT'S COLD!");
                  }
             else
             if ( temp > 30 )
                 {
                 min("IT'S HOT!");
                 }
            else
                {
                min("COOL CLIMATE!");
                }
       getch ();
       return 0;
       }
                                                                      Sample Outputs:



                 

                                                                        ▌▌▌Ü ▌▌▌

Problem number 8

Write a program segment that will ask the user if he wants to compute the perimeter or the area of a triangle. If the perimeter is wanted, ask the measure of the three sides and compute for the perimeter. If the are is wanted, ask for the measures of the base and height and compute for the area. Display the computed value.
 

     #include<stdio.h>
     #include<conio.h>
     #define min printf
     #define jee scanf

     int main()
     {
         int peri, s1, s2, s3, base, height;
         char choice;
         float area;
   
         min("What do you want to solve?");
         min("\nP - Perimeter \nA - Area");
         min("\nEnter choice: ");
         jee("%s",&choice);
   
         switch(choice)
          {
                case 'P':
                     {
                     min("Enter side #1: ");
                     jee("%d",&s1);
                     min("Enter side #2: ");
                     jee("%d",&s2);
                     min("Enter side #3: ");
                     jee("%d",&s3);
                 
                     peri = s1 + s2 + s3;

                     min("The perimeter of the triangle is %d",peri);
                     break;
                     }
 
              case 'A':
                     {
                     min("Enter base: ");
                     jee("%d",&base);
                     min("Enter height: ");
                     jee("%d",&height);
               
                     area = (base * height)*.5;
               
                     min("The area of the triangle is %.2f",area);
                     break;
                     }
                     } 
          getch ();
          return 0;
}
                                                                    Sample Outputs:


         
                                                                       ▌▌▌Ü ▌▌▌

Biyernes, Oktubre 7, 2011

Lesson namo saturday(Oct. 8, 2011)

*Review sa DEVC++ lessons...

-Conditional Statements:
◘◘Sample #1:
•Create a program that will display the largest inputted value!

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

   int main()
   {
          int x,y;
      
          printf("Enter value for x :");
          scanf("%d",&x);
          printf("Enter value for y :");
          scanf("%d",&y);
      
          if ( x > y )
          {
                  printf("X is large number - %d\n",x);
          }
          else
          {
                 printf("Y is large number - %d\n",y);
          }
          getch();
          return 0;
}

◘◘Sample #2 :
 •Write a program that will display "Pretty Young" if age is lesser than 18, and will display "You Old" if age 
    is  greater than 18.

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

   int main()
   {
          int age;
       
          printf("Enter age:");
          scanf("%d",&age);
      
          if ( age <= 18 )
         {
               printf("Pretty Young!");
         }
         else      
        {
               printf("Your Old!");
       }
       getch();
       return 0;
}

Huwebes, Setyembre 15, 2011

IT-403 Assignment(share lang)



Sa mga wala kanina...gawin niyo yan :)
I-drag lang ang image o i-download :D

Advance Merry Christmas Mga Higala

Share lang ako ng mga Favorite quotes sa inyo this up coming Christmas :)


"I have always thought of Christmas time, when it has come round, as a good time; a kind, forgiving, charitable time; the only time I know of, in the long calendar of the year, when men and women seem by one consent to open their shut-up hearts freely, and to think of people below them as if they really were fellow passengers to the grave, and not another race of creatures bound on other journeys. " :Ma3e:


"Happy, happy Christmas, that can win us back to the delusions of our childish days; that can recall to the old man the pleasures of his youth; that can transport the sailor and the traveller, thousands of miles away, back to his own fire-side and his quiet home! "  :Ma3e:


"Instead of being a time of unusual behavior, Christmas is perhaps the only time in the year when people can obey their natural impulses and express their true sentiments without feeling self-conscious and, perhaps, foolish.  Christmas, in short, is about the only chance a man has to be himself. "  :Ma3e: