Saturday, 31 August 2013

Write a program to find the factorial value of any number entered through the keyboard using for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,fact=1;/*Intialization of factorial , if u dont  then garbaage value is add in the value of Factorial*/
printf("Enter a number to calculate its factorial");
scanf("%d",&n);
for (i=1;i<=n;i++)/*if i will be great the n,so the loop will terminate*/
fact=fact*i;
printf("factorial of %d=%d",n,fact);
getch();
}

Sunday, 28 April 2013

write a program that generates a table of any number using for loop



#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int cols,rows;
for(rows=1;rows<=10;rows++)
{
for(cols=2;cols<3;cols++)
printf("%3d",cols*rows);
printf("\n");
}
getch();
}
/*remember :rows loop is arrived preceding int and after this cols loop,if you cant, your program doesn't work properly */
for increasing more tables inrement in rows and cols value
steay blessed