The if statement controls conditional branching.The body of an if statement is executed if the value of the expression is nonzero.The if statement allows you to control if a program enters a section of code or nor based on whether a given condition is true or false.One of the important function of the if statement is that it allows the program to select an action based upon the user's input.For example we can check user entered password by using if statement,and decide whether a user is allowed access to the program.
Syntax ...
Tuesday, June 28, 2011
C PROGRAM TO REVERSE A NUMBER USING WHILE LOOP
/*Program to reverse a number using while loop*/#include<stdio.h>void main(){long int number,reverse,n;clrscr();printf("Enter the number");scanf("%ld",&number);reverse=0;while(number!=0){n=number%10;reverse=reverse*10+n;number=number/10;}printf("The reverse number=%ld\n",reverse);getch( ...
TO FIND THE SUM OF DIGITS IN A FIVE DIGIT NUMBER
#include<stdio.h>
void main(){int digit_1,digit_2,digit_3,digit_4,digit_5,sum,number,n;printf("Enter a five digit number");scanf("%d",&number);n=number;digit_1=n%10;n=n/10;digit_2=n%10;n=n/10;digit_3=n%10;n=n/10;digit_4=n%10;n=n/10;digit_5=n;sum=digit_1+digit_2+digit_3+digit_4+digit_5;printf("sum of digits=%d\n",sum);getch() ...
Monday, June 27, 2011
How Use Loops in C-'DO WHILE' Loops
'DO WHILE' loops are useful for things that want to loop at least once.The syntax is:
do
{
Code to execute
}while(condition);
Example:
#include<stdio.h>
int main()
{
int x;
x=0;
do
{/*"Hello World!" is printed at least one time even though the condition is false*/
printf("Hello World!");
}
while(x!=0);
getchar();
}
Notice that the condition is tested at the end of the block instead of beginning ,so the block will be executed at least once.If the condition is true,we jump back to the beginning of the block and execute it again.A DO WHILE loop is almost the same ...
Sunday, June 26, 2011
How Use Loops in C-'While' Loops
WHILE loops are very simple and the syntax is:
while(condition)
{
Code to execute while the condition is true
}
The true represent a boolean expression which could be while(x==1) or while(x!=7),x does not equal to 7.It can be any combination of boolean statements that are legal.Even, while(x==5||y==7) which says execute the code while x equal to 5 or y equal to 7.
Example:
To print numbers up to 10:
#include<stdio.h>
int main()
{
int x=0; /*Don't forget to declare variables*/
while(x<10) /*while x less than 10*/
{
printf("%d",x);
x++; /*Update x ...
How Use Loops in C-'FOR' Loops
Loops are used to repeat a block of code.Loops are one of the most basic but useful task in programming.We can simply produce extremely complex out put using loops.A loops let you write a very simple statement to produce a significantly greater result simply by repetition.
FOR LOOPS:
FOR loops are the most useful one.The syntax of FOR loops:
for(variable initialization; condition; variable update)
{
code to execute while the condition is true
}
Example:
To print numbers upto 10:
#include<stdio.h>
int main()
{
int x;
/* ...
Thursday, June 23, 2011
Shiny Text-C Program

We can able to create shiny text using simple and small C code.Copy and Paste the below code into your TURBO C++ 3.0 complier.Run the program.You can see its effect on colored monitor.
Source Code:
#include<stdio.h>
#include<conio.h>
int main()
{
char *name;
int len,count,place,row;
clrscr();
textbackground(0);
printf("\n Enter Your Name : ");
gets(name);
len=strlen(name); // Find the Length of name
for(count=0;count<=len;count++)
{
row=30;
for(place=0;placelen;place++)/len;place++)
{
if(place==count)
{
textcolor(13);
gotoxy(row++,10);
cprintf("%c",name[count]);
}
else
{
textcolor(10);
gotoxy(row++,10);
cprintf("%c",name[place]);
}
}
delay(200); ...
Tuesday, June 21, 2011
C Program to Play Wave File

Hi Friends,here we will discuss about how to play a Wave file using C program.i found source code to play Wave file.Copy and Paste ,compile using Turbo C++ 3.0.
Source Code:
//Include files
#include "ALLOC.H"
#include "DOS.H"
#include "CONIO.H"
#include "STDIO.H"
void playwav(char wavefile[14],float delaytime);
struct WaveData {
unsigned int SoundLength, Frequency;
char *Sample;
};
struct HeaderType {
long ...
Thursday, June 16, 2011
How to Compile C in Linux

How to Compile C program in Linux/Unix ?:
Some people have doubts about how to compile C source code in Linux/Unix.Firstly you need GNU project C and C++ compiler for compiling C program and create executable(EXE) file.Most Linux and Unix user start compiling their C program by the name cc.But you can use gcc command to compile program.
First make sure you have gcc installed.
Type the following Command in Terminal to verify that gcc is installed:which ...
Monday, June 13, 2011
UBUNTU LINUX 11:04 REVIEW

Ubuntu Linux released new version of Ubuntu named as Ubuntu 11:04 Natty Narwhal. Normally Ubuntu considered as Linux based Windows.About 12 million Desktop computer running under Ubuntu operating system.Ubuntu OS differed from other Linux OS by it's easy to use ability.
...
Sunday, June 12, 2011
MAKE SIMPLE GAME IN C

Hi friends,here we will make a simple Game in C language.Enjoy C programming.Compile below code and Generate EXE file.
Source code of Game:
#include <stdio.h>#include <conio.h>#include <dos.h>#include <graphics.h>#include <stdlib.h>#include <time.h>
#define PAS 20
struct time t;int keye=250;int coordX=0;int coorde=0;int coordY=0;int coordYe=0;int tmp=0;int tmp2=0;int i;
void moveMyshipLeft(void);void moveMyshipRight(void);void moveMyshipUp(void);void moveMyshipDown(void);void desenMyShip(int,int,int);
void getConflict(it ...
Subscribe to:
Posts (Atom)