# KCS151/KCS251 PPS Lab Exercise Program: 17

## LAB Exercise Program: 17

#### KCS151P/KCS251P

##### LAB 4

Write a program to find the sum of the Fibonacci series using a function.

Write factorial function & use the function to find the sum of series S = 1! + 2! + … + n!

##### LAB 5

Write a program to find the factorial of the given number using recursion.

Write a program to find the sum of digits of a 5 digit number using recursion.

Write a program to calculate the GCD of given numbers using recursion.

Write a program to convert a decimal number into a binary number.

Write a program to convert a binary number into a decimal number.

##### LAB 6

Write a program to delete duplicate element in a list of 10 elements & display it on screen.

Write a program to merge two sorted arrays & no element is repeated during merging.

Write a program to evaluate the addition of diagonal elements of two square matrixes.

Write a program to find the transpose of a given matrix & check whether it is symmetric or not.

Write a program to print the multiplication of two N*N (Square) matrix.

##### LAB 7

Write a program in C to check whether the given string is a palindrome or not.

Write a program to sort the array of characters (String) in alphabetical order like STRING in GINRST.

Write a program to remove all the blank space from the string & print it, also count the no of characters.

Write a program to store the following string “zero”, “one”, … “five”.
Print the no in words, given in figure as 3205.

##### LAB 8

Write a program to compare two given dates. To store a date uses a structure that contains three members namely day, month, and year. If the dates are equal then display message equal otherwise unequal.

Define a structure that can describe a hotel. It should have the member that includes the name, address, grade, room charge, and the number of rooms.
Write a function to print out the hotel of given grade in order of room charges.

Define a structure called cricket with player name, team name, batting average, for 55 players & 5 teams. Print team-wise list contains names of players with their batting average.

##### LAB 9

Write a C program to copy & count the character content of one file, says a.txt to another file b.txt.

Write a program to take 10 integers from a file and write the square of these integers in another file.

Write a program to read numbers from a file and then write all ‘odd’ numbers to file ODD.txt & all ‘even’ to file EVEN.txt.

Write a program to print all the prime numbers, between 1 to 100 in file prime.txt.

Write the following C program using pointer:
a) To sort the list of numbers through the pointer.
b) To reverse the string through the pointer.

##### LAB 10

Write a program to find the largest no among 20 integers array using dynamic memory allocation.

Using Dynamic Memory Allocation, Write a program to find the transpose of the given matrix.

Write a program to find the factorial of the given number using the command line argument.

Write a program to find the sum of digits of a 5 digit number using the command line argument.

## 17. Write a program to calculate the factorial for given number using function.

				
/*
File: Prgrm17.c
Date: Jan 17, 2021
Description: Program to calculate the factorial for the given number using a function.
*/

#include <stdio.h>

int factorial (int);

int main (void)
{
int num;
int fact;

//Input number
printf ("Input number: ");
scanf ("%d", &num);

//Function call
fact = factorial (num);

//Print result
if (fact > 0)
{
printf ("Factorial: %d", fact);
}

return 0;
};

int factorial (int num)
{
int fact;
int i;

//Calculate factorial
fact = 1;
if (num >= 0)
{
for (i = 1; i <= num; i++)
fact = fact * i;
return fact;
}
else
{
printf ("Error! Negative number");
return -1;
}
};



Stdin Inputs:

5

Sample Result:

Input number: 5
Factorial: 120
{"ft_lang_label":"__label__en","ft_lang_prob":0.7959826,"math_prob":0.9621372,"size":3812,"snap":"2022-40-2023-06","text_gpt3_token_len":921,"char_repetition_ratio":0.20929621,"word_repetition_ratio":0.11637931,"special_character_ratio":0.25341028,"punctuation_ratio":0.12564766,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9943575,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-02-09T05:16:47Z\",\"WARC-Record-ID\":\"<urn:uuid:3b98ed41-7e13-458a-a662-5f578d4b2294>\",\"Content-Length\":\"353261\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6b4791c1-72e6-46ac-876c-4eea4a4061f9>\",\"WARC-Concurrent-To\":\"<urn:uuid:419cb6ec-55aa-4d02-b546-0733293d944e>\",\"WARC-IP-Address\":\"104.21.76.120\",\"WARC-Target-URI\":\"https://www.digitalg1.com/courses/kcs101-kcs201-pps/kcs151p-kcs251p-c-program-17/\",\"WARC-Payload-Digest\":\"sha1:67D7MXONFBPULB6RHVSTKUZFFZO4CJ6J\",\"WARC-Block-Digest\":\"sha1:TYAF4GFDTFIPCALG2YH4E5KZRPLNLNGB\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764501407.6_warc_CC-MAIN-20230209045525-20230209075525-00628.warc.gz\"}"}