NO

Author Topic: Simple Programs  (Read 4190 times)

michaeled314

  • Guest
Simple Programs
« on: April 06, 2007, 01:42:35 AM »
Here are a few simple programs for beginners!!

Basic Hello World:

Code: [Select]
#include <stdio.h>

int main()
{
      printf("Hello World\n");
      return 0;
}

Guess the Number (note the random seed is being set to the current system time):
Code: [Select]
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
int range,num, guessnum, tries;
printf("Upper Range PIease: ");
scanf("%d",&range);
srand(time(0));

num = (rand() % range) + 1;


while (guessnum != num)
{
printf("Enter a Number: ");
scanf("%d", &guessnum);
tries = tries + 1;

if (guessnum < num)
{
printf("Too low\n");
}

if (guessnum > num)
      {
printf("Too high\n");
}
}

printf("You guessed it\n");
return 0;
}