Lab#03 F.
No#4497
Object: To print the factorial of a number given by user.
Source Code:
#include <stdio.h>
#include<conio.h>
void main(void)
{
int d1, d2, d3= 1;
printf("Enter a number to calculate it's factorial: ");
scanf("%d", &d2);
for (d1 = 1; d1 <= d2; d1++)
d3 = d3 * d1;
printf("Factorial of %d = %d\n", d2, d3);
getch();
}
Output:
Computer Fundamentals & Programming 1
Lab#03 F.No#4497
Object: To print the even and odd numbers and also table of a number given by user using
for loop.
Source Code:
#include <stdio.h>
#include<conio.h>
void main(void)
{
int even,odd,count,ch;
odd=1;even=2;count=1;
for(;count<=5;count++)
{
printf("Even=%d\tOdd=%d ",even,odd);
even+=2; odd+=2;
printf("\n");
}
ch='y';
while(ch=='y')
{
printf("\nEnter a number to generate a table: ");
scanf("%d", &odd);
for(count= 1; count <= 10; count++)
{
printf("%d*%d=%d \n",odd,count,count*odd);
}
printf("Do you want to continue program:");
ch=getche();
}
}
Output:
Computer Fundamentals & Programming 2
Lab#03 F.No#4497
Object: To print the even and odd numbers and also table of a number given by user using
while loop.
Source Code:
#include <stdio.h>
#include<conio.h>
void main(void)
{
int even,odd,count,ch;
odd=1;even=2;count=1;
while(count<=5)
{
printf("Even=%d\tOdd=%d ",even,odd);
even+=2; odd+=2; count++;
printf("\n");
}
ch='y';
while(ch=='y')
{
printf("\nEnter a number to generate a table: ");
scanf("%d", &odd);
count=1;
while(count <= 10)
{
printf("%d*%d=%d \n",odd,count,count*odd);
count++;
}
printf("Do you want to continue program:");
ch=getche();
}
}
Output:
Computer Fundamentals & Programming 3
Lab#03 F.No#4497
Object: To print the Increament/Decrement of a number.
Source Code:
#include <stdio.h>
#include<conio.h>
void main(void)
{
int count;
clrscr();
count=0;
printf("\n count=%d",count++);
printf("\n\n count=%d",count--);
printf("\n\n count=%d",count--);
printf("\n\n count=%d",++count);
getch();
}
Output:
Computer Fundamentals & Programming 4
Lab#03 F.No#4497
BIODATA
Name: Mohammad Babar Munir
F.Name: Wasif Akhtar Siddique
Qualification: INTER
Phone: 03422218200
Address: R-274 sec-16 A bufferzone
University: Sir Syed University Of Engineering Technology.
Form number: 4497
Discipline: EE
Subject: Computer Fundamentals and Programming
Teacher: Sir Sarfaraz Nattha
Computer Fundamentals & Programming 5