Posts

Showing posts from November, 2010

C Data Types

Data types are used to store various types of data that is processed by program. Data type attaches with variable to determine the number of bytes to be allocate to variable and valid operations which can be performed on that variable. C supports various data types such as character, integer and floating-point types. Character Data Type C stores character type internally as an integer. Each character has 8 bits so we can have 256 different characters values (0-255). Character set is used to map between an integer value and a character. The most common character set is ASCII. Let take a look at example of using a variable which hold character 'A'. #include  void main()  {  char ch = 'A';  printf("%c\n",ch);  ch = 65;                     // using integer representation  printf("%c\n",ch);  ch = '\x41';               // using hexadecimal representation ...

Getting Started with C.

The C program is a set of functions. A C program always starts executing in a special function called main function. Here is the simple but famous "Hello World" program which prints "Hello World" greeting to screen. #include void main() { printf("Hello World!\n"); } The first line is the the #include directive. C program uses this directive to load external function library - stdio is c library which provides standard input/output. printf is a function which is declared in the header file called stdio.h The next is the main function - the first entry point of all C programs. C program logic starts from the beginning of main function to the its ending. And finally is the printf function which accepts a string parameter. The printf function is used to print out the message to the screen.

C Language (Switching Values)

#include #include void main() { int a,b,c; a=10; b=25; printf("\nThe Value of A is %d",a); printf("\nThe Value of B is %d",b); c=a; a=b; b=c; printf("\nNow the Value of A is %d",a); printf("\nNow the Value of B is %d",b) ; getch(); }

C Language (Leap Year)

#include #include void main() { int year; clrscr(); printf("Enter Year "); scanf("%d",&year); if (year%4==0 && year%100!=0) printf("\n This is leap year"); else printf("\n This is not leap year"); getch(); }

C Language (Functions)

#include #include char ucase(); void main() { char ch1; clrscr(); ch1 = ucase(); printf("\n The Character is %c",ch1); getch(); } char ucase() { char ch; ch = getche(); if (ch>=65 && ch =97 && ch ch=ch-32; return(ch); }

C Language (Fibonacci Series)

#include #include void main() {  int a,b,c,e;  printf("Enter End Value ");  scanf("%d",&e);  clrscr();  printf("\n Generate Fibonacci Numbers till %d",e);  a=0;  b=1;  c=a+b; printf("\n \n %d , %d , %d",a,b,c);  while (c  {  a=b;  b=c;  c=a+b;  printf(", %d",c);  }  getch(); }

C Language (Fibonacci Series)

#include #include void main() {  int a,b,c,e;  printf("Enter End Value ");  scanf("%d",&e);  clrscr();  printf("\n Generate Fibonacci Numbers till %d",e);  a=0;  b=1;  c=a+b; printf("\n \n %d , %d , %d",a,b,c);  while (c  {  a=b;  b=c;  c=a+b;  printf(", %d",c);  }  getch(); }

C Language (Character Print)

#include #include void main() {  int a;  char ch;  clrscr();  for (a=65;a<=90;a++)  {  ch = a;  printf("\n %d ",a);  printf("  =    %c",ch); } getch(); }

C Language (Arrays)

#include #include void main() { clrscr(); int a[7]; int b,c=5; for (b=1;b<=5;b++) { a[b] = c; c++; } for (b=0;b<=7;b++) { printf("\n The No. a(%d) is %d",b,a[b]); } getch(); }

C Language (Prime No.)

#include #include void main() {  int n,i,j,c;  clrscr();  printf("Enter Starting Value");  scanf("%d", &i);  printf("Enter Ending Value");  scanf("%d",&n); while (i<=n)  {  c=0;  for (j=1;j<=i;j++)  {   if(i%j==0)   c++;   }   if (c==2)  printf("\n %d    ",i);  i++;  }   getch(); }

C Language (Factorial) While Loop

#include #include void main() {  clrscr();  long a,b;  printf("Enter value");  scanf("%ld",&a);  b=a;  printf("\n %ld",b);  while(a>1)   {  a--;  printf(" * %ld" ,a);  b=b*a;       }   printf(" = %ld",b);   getch(); }

C Language (Factorial) Do while loop

#include #include void main() {  clrscr();  long a,b;  printf("Enter value");  scanf("%ld",&a);  b=a;  printf("\n %ld",b);  do    {  a--;  printf(" * %ld" ,a);  b=b*a;       }   while (a>1);   printf(" = %ld",b);   getch(); }

C Language (Time Table) DO While Loop

#include #include void main() {  clrscr();  int a,c,s;  printf("Enter value");  scanf("%d",&s);  a=1;  do   {   c=s*a;  printf("\n %d", s);  printf(" x ");  printf("%d",a);  printf(" = ");  printf("%d" ,c); a++;   }   while (a<=10);  getch(); }

C Language (LOOP)

#include #include void main() {  clrscr();  int a;  for (a=0;a<=10;a++)  printf("\n The loop is %d", a);  getch(); }

C Language (Time Table) While Loop

#include #include void main() {  clrscr();  int a,c,s;  printf("Enter value");  scanf("%d",&s);  a = 1;  while (a<=10)   {   c=s*a;  printf("\n %d", s);  printf(" x ");  printf("%d",a);  printf(" = ");  printf("%d" ,c);   a++;   }  getch(); }

C Language (Time Table)

#include #include void main() {  clrscr();  int a,c,s;  printf("Enter value");  scanf("%d",&s);  for (a=1;a<=10;a++)   {   c=s*a;  printf("\n %d", s);  printf(" x %d",a);  printf(" = %d" ,c);   }  getch(); }

C Language (Conversion Celcius b/w farheniet)

#include #include void main() {  clrscr();  int a,e,s,o;  printf("For Even Nos type 1 and for ODD Nos type 2");  scanf("%d",&o);  printf("\n Enter starting value");  scanf("%d",&s);  printf("\n Enter End Value");  scanf("%d",&e);  if (o==1)  {  if (s%2!=0)  {  s++;  } }  if (o==2)  { if (s%2==0)  { s++; }}  for (a=s;a<=e;a++,a++)  printf("\n The loop is %d", a);  getch(); }

C Language (Conversion Celcius to Farheniet)

#include #include void main() { float c,f; clrscr(); printf ("Enter Value"); scanf ("%f",&c); f = (c+32)*9/5; printf("The ans is %f",f); getch(); }

C Language (Area of the ROOM)

#include #include void main() { int l,b,p; clrscr(); printf ("Enter Value"); scanf ("%d,%d",&l,&b); p=(2*l)+(2*b); printf("The ans is %d",p); getch(); }

C Language EVEN OR ODD NO.

#include #include void main() { int a; clrscr(); printf ("Enter Value"); scanf ("%d",&a); if (a%2==0) { printf("This is EVEN No."); } else printf("This is ODD No."); getch(); }

C Language Program1

#include #include void main( ) { printf ("This is a line of text to output."); }