Thursday, May 16, 2013
Let's start c programming...
-->
Start with a simple program to print a "Hello World" message on screen and i will tell what does the commands in it.
#include<stdio.h>
main()
{
printf("Hello World \n");
}
#include<stdio.h>
C programs are divided into modules or functions. Library functions are grouped category-wise and stored in different files known as header files. It is necessary to tell the compiler about the files to be accessed for accessing it.
#include<name>
#include<stdio.h> includes the files that performs standard input output operations.
main()
main is a part of all C program.
printf("Hello World \n")
printf command for printing output into screen.
A simple program to understand function of #define..
#include<stdio.h>
#define N 10
main()
{
int count;
float sum,average,number;
sum=0;
count=0;
while(count<N)
{
scanf("%f",&number);
sum=sum+number;
count=count+1;
}
average=sum/N;
printf("N=%d Sum=%f",N,sum);
printf("Average=%f",average);
}
In above program N is taken as a constant value.
Here N=10. When "average=sum/N;" loads value of N loaded from "#define N 10".
Program to understand scanf function...
#include<stdio.h>
main()
{
int a;
scanf("%d",&a);
printf("%d",a);
}
Above program will show you function of scanf.
While executing above program the cursor blinks. That indicates program need input from you.
This program print the input what you typed.
In scanf("%d",&a);
&a is the instruction to save your input into a.
(This program for linux. In turbo c you must return a value)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment