Showing posts with label C-ANSI. Show all posts
Showing posts with label C-ANSI. Show all posts

Saturday, 6 December 2014

Factorial Calculator in C


//this is a small program that will get you how to calculate factorial in C


//------------------------------------------------------------------------------
#include<stdio.h>

#include <conio.h>
int main()
{
int w=1, x ,  y , z=1;


printf("factorial theorem\n");


scanf("%d",  &y );


for (x=1;x<y ; x++){

    z=x*z;

    printf("%d!=%d\n",w, z);
    w++;
    
}

getch();


}


/*
x=loop variable.......
y=limit of table
w=value--jis ka factorial at the moment liya jaa rha hai i.e. 0! ,1!,2!....
z= answer of factorial
*/

Let's Start with C Programming - 1st program

Let us start with C-ANSI programming. 
I will post all the material of C programming as much as I learnt.

Actually C was 1st programming language that I learn , to Complete Course Requirements of My 1st Semester of Electrical Engineering. I really Enjoyed this Course, after 6 months of starting it , i can make conversation in 5 Different programming languages.

let's start with 1st program, that is Assalam u Alikum World program

C code 
 //-----------------------------------------------------------------------------

#include<stdio.h>
int main()
{
printf("Assalam u Alikum World \n"); 
return 0;
}
//------------------------------------------------------------------------------
the above code segment is 1st program of C language which is usually taught.

#include<stdio.h>
this line indicates compiler to include library named in "<>"
Stdio.h is standard Input Output Library in C.

Int main()
 it indicates initialization of main function of integer type.
At this stage i will only say that C language program  includes many function, and "main" function is most important , in which we write the basic code.

{}
these brackets indicate boundary of a block/function.

printf("Assalam u Alikum World \n");
printf() is function for displaying something as output on screen.

return 0 ;
indicates successful termination.



For C language I will Recommend Following Books
The C programming Language By Brian W. Kernighan and Dennis M. Ritchie.
 C How to Program by Dietel and Dietel