LIVE TV

c programmes


Geo maze se::-
Geet ke geo::-

-------------------------------------------------------------------------------------------------------------


/* FINDING Maximum Values */

#include <stdio.h>
#include <limits.h>
#include <float.h>

int
main (void)
{
   printf ("The largest integer is: %d\n", INT_MAX);
   printf ("The largest double is: %e\n", DBL_MAX);

   return (0);
}

----------------------------------------------------------------------------------------------------------
Programme in c to Find substring in main string:
#include<stdio.h>
#include<conio.h>
int main()
{
 int i=0,j=0,k=0,count=0,l=0,k1=0;
 char a[80],b[80];

 clrscr();
 printf("\nEnter main string:-\n");
 gets(a);
 printf("\nEnter sub-string:-\n");
 gets(b);
 l=strlen(b);

 while (a[i]!=EOF)
  {
     if (a[i]==b[j])
      {
        i++;
        j++;
        k1=1;
       
        if (j==l)
          {
            j=0;
            k=1;
            count=count+1;
          }
     }
    else
     {
       if (k1==1)
          {
           j=0;
           k1=0;
          }
       else
          i++;
    }
 }
 if (k==1)
  {
     printf("\n\nThe given sub-string is present in the main string.");
     printf("\nIt is present %d times.",count);
  }
 
 else
  {
     if (k==0)
     printf("\n\nThe given sub-string is not present in the main string.");
  }

}


                 --------------------------------------------------------------------------


Write a programme in c to find |Even or odd numbers:


int main ()
{
int x;
printf ("Enter the value of x\n");
scanf ("%d",&x);
if (0 == x%2)
printf ("Number is even\n")
else
printf ("Number is odd\n");
}


              ------------------------------------------------------------------


#include<stdio.h>
#include<conio.h>
void main()
{
int i=0;
char str[10];
clrscr();
printf("Enter the string:");
scanf("%c",str);
while(str[i]!='\0')
i++;
for(i=0;str[i]!='\0';i++)
{
str1[j]=str[i];
j++;
}
str1[j]='\0';
printf("Reverse of a given string:",str1);
getch();
}
                     --------------------------------------------------------------
#include <iostream>

bool IsPrime(int num)
{
if(num == 0)
return true;

num = abs(num);

for(int i = 2; i <= sqrt(num); i++)
if(num % i == 0)
return false;

return true;
}

            --------------------------------------------------------------------------


The random  function programme in C..... ????

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

int
main (void)
{
  /* initialize random generator */
  srand (time(NULL));

  /* generate random numbers */
  printf("RAND_MAX = %d\n", RAND_MAX);
  printf ("A number between 0 and RAND_MAX : %d\n", rand());
  printf ("A number between 0 and 99: %d\n", rand() % 100);
  printf ("A number between 0 and 9: %d\n", rand() % 10);
  printf ("A number between 1 and 6: %d\n", (rand() % 6) + 1);
 
  return (0);
}
---------------------------------------------------------------------------------------------------------


/* Problem: This is just a silly program playing with pointers */
#include <stdio.h>

int
main (void)
{
   /* a and e are integers */
   int a, e; 

   /* b is a pointer to an integer */
   int* b;

   /* c is a pointer to a pointer to an integer */  
   int** c;

   /* d is a pointer to a pointer to a pointer to an integer */
   int*** d;    

   a = 25;   /* a contains the integer 25 */
   b = &a;   /* b contains the address of a */
   c = &b;   /* c contains the address of b */
   d = &c;   /* d contains the address of c */

   /* Do you understand that ***d is actually a? */
   e = ***d * 2;  

   printf ("%d", e);

   return (0);
}


---------------------------------------------------------------------------------------------------------


/* Comparing two strings */



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


int
main (void)
{

char city1[50], city2[50];
int comp;


printf ("Comparison of two city names\n");
printf ("============================\n\n");

printf ("Enter the name of the first city (<50 letters): ");
gets (city1);
printf ("Enter the name of the second city (<50 letters): ");
gets (city2);

/* strcmp compares two strings */
comp = strcmp (city1, city2);

if (comp < 0)
printf ("\n\n%s < %s.\n", city1, city2);
else
if (comp == 0)
printf ("\n%s = %s.", city1, city2);
else
printf ("\n%s > %s.", city1, city2);

return (0);
}

--------------------------------------------------------------------------------------------------------



/* Reading a string from a file */

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


int
main (void)
{
char sentence[200];
FILE *input;


/* file is opened */
input = fopen("phrase.txt", "r");

/* the string is read from the file */
fgets (sentence, sizeof(sentence), input);

/* sentence is echoed on the screen */
/* \" to display a " (double quotes) */
printf ("The sentence is:\n\"%s\"\n\n\n", sentence);

/* file is closed */
fclose (input);

return (0);
}


--------------------------------------------------------------------------------------------------------


/* Manipulating strings */

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


/* This function takes a string and returns
another all in uppercase letters */

void
uppercase (
char in[], char out[])
{
       
int i;
        /* transforms letters in uppercase one by one */
        for (i=0; i<=strlen(in); ++i)
               out[i] = toupper(in[i]);
}



/* This function takes a string and returns
another with only the letters */

void
onlyletters (
char in[], char out[])
{
        int i, j;
       
/* j is the counter for the new string */
        j=0;
        for (i=0; i<=strlen(in); ++i)
        {
              
/* sends char to new string only if letter */
               /* must send also the end-of-string character */

               if (isalpha(in[i]) || in[i]=='\0')
               {
                       out[j] = in[i];
                       j=j+1;
               }
        }
}



int
main (void)
{
char before[50], after[50];

printf ("Enter a phrase: ");
gets (before);
printf ("Original sentence: %s.\n", before);

uppercase (before, after);
printf ("In uppercase: %s.\n", after);

onlyletters (before, after);
printf ("Only the letters: %s.\n", after);

return (0);
}

------------------------------------------------------------------------------------------------------------





/* An example of structures */

#include <stdio.h>

/* the planets structure */
typedef struct
{
char name [10];
double diameter;
int moons;
double orbit, rotation;
} planets_t;


/* the solar systems structure contains a planets type element */
typedef struct
{
double diameter;
planets_t the_planets[9];
char galaxy [10];
} solar_systems_t;


int
main(void)
{
planets_t planet = {"Earth", 1000, 1, 1.0, 24.0};
solar_systems_t solarsystem;


printf ("The planet %s has %d moon(s).\n", planet.name, planet.moons);

solarsystem.the_planets[2] = planet;

strcpy (planet.name, "Jupiter");
planet.diameter = 142980;
planet.moons = 16;
planet.orbit = 11.9;
planet.rotation = 9.925;

printf ("Planet %s has %d moon(s).\n", planet.name, planet.moons);
printf ("Planet %s has %d moon(s).\n", solarsystem.the_planets[2].name,
solarsystem.the_planets[2].moons);

return(0);

}

-----------------------------------------------------------------------------------------------------------


/* Dynamic allocation of a 2D array */
/* (Computer Scientist's Method) */

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


/* Dynamic allocation of arrays of more than one dimension
can also be done using a pointer pointing to an array of
pointer and each pointer of that array pointing to an array
of values. With that method you can use the real 2-D
subscripts like array[i][j] */


int
main (void)
{
int nrows, ncols, i, j;
int **numbers;
/* pointer to the first cell ([0][0]) */

printf ("How many rows and columns?> ");
scanf ("%d%d", &nrows, &ncols);

/* allocating the array of pointers */
numbers = (int **) calloc (nrows, sizeof(int *));

/* allocating the array of integers */
for (i=0; i<nrows; ++i)
numbers[i] = (int *) calloc (ncols, sizeof(int));

i=1; j=1;
numbers[i][j] = 9; /* initializes one value to 9 */


for (i=0; i<nrows; i=i+1)
{
for (j=0; j<ncols; j=j+1)
{
printf ("%3d ", numbers[i][j]);

}
printf ("\n");
}

/* freeing the array */
for (i=0; i<nrows; ++i)
free (numbers[i]);

free (numbers);

return (0);
}


-----------------------------------------------------------------------------------------------------------







Some of our Friends who can help you in c programming::
1) http://c.ihypress.ca/
2) http://www.lix.polytechnique.fr/~liberti/public/computing/prog/c/C/EXAMPLES/examples.html
3) http://www.it.iitb.ac.in/~sudhir/Programming/Intresting_C_Problems.html
4) http://www.cprogramming.com/
5) http://www.cprograms.in/
6) http://www.freecprograms.com/