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)
{
srand (time(NULL));
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);
}
---------------------------------------------------------------------------------------------------------
#include <stdio.h>
int
main (void)
{
int a, e;
int* b;
int** c;
int*** d;
a = 25;
b = &a;
c = &b;
d = &c;
e = ***d * 2;
printf ("%d", e);
return (0);
}
---------------------------------------------------------------------------------------------------------
#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);
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);
}
--------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
int
main (void)
{
char sentence[200];
FILE *input;
input = fopen("phrase.txt", "r");
fgets (sentence, sizeof(sentence), input);
printf ("The sentence is:\n\"%s\"\n\n\n", sentence);
fclose (input);
return (0);
}
--------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void
uppercase (char in[], char out[])
{
int i;
for (i=0; i<=strlen(in); ++i)
out[i] = toupper(in[i]);
}
void
onlyletters (char in[], char out[])
{
int i, j;
j=0;
for (i=0; i<=strlen(in); ++i)
{
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);
}
------------------------------------------------------------------------------------------------------------
#include <stdio.h>
typedef struct
{
char name [10];
double diameter;
int moons;
double orbit, rotation;
} planets_t;
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);
}
-----------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
int
main (void)
{
int nrows, ncols, i, j;
int **numbers;
printf ("How many rows and columns?> ");
scanf ("%d%d", &nrows, &ncols);
numbers = (int **) calloc (nrows, sizeof(int *));
for (i=0; i<nrows; ++i)
numbers[i] = (int *) calloc (ncols, sizeof(int));
i=1; j=1;
numbers[i][j] = 9;
for (i=0; i<nrows; i=i+1)
{
for (j=0; j<ncols; j=j+1)
{
printf ("%3d ", numbers[i][j]);
}
printf ("\n");
}
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/