0% found this document useful (0 votes)
53 views5 pages

Object: To Print The Factorial of A Number Given by User. Source Code

This document contains the source code and output for 4 programs from a student's computer science lab assignment. The first program prints the factorial of a number input by the user. The second program prints even and odd numbers using a for loop and generates a multiplication table for a user-input number. The third is similar but uses a while loop instead of a for loop. The fourth program demonstrates incrementing and decrementing a variable.

Uploaded by

Babar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views5 pages

Object: To Print The Factorial of A Number Given by User. Source Code

This document contains the source code and output for 4 programs from a student's computer science lab assignment. The first program prints the factorial of a number input by the user. The second program prints even and odd numbers using a for loop and generates a multiplication table for a user-input number. The third is similar but uses a while loop instead of a for loop. The fourth program demonstrates incrementing and decrementing a variable.

Uploaded by

Babar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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

You might also like