HW5 Solutions
HW5 Solutions
Exercise 1.
/**
* C program to print hollow diamond star pattern program to print hollow diamond star pattern to print hollow diamond star pattern diam to print hollow diamond star patternond star pattern
*/
#include <stdio.h>
void printhollow diamond star patterndiam to print hollow diamond star patternond(int n)
{
int i,j;
// Loop to print upper half of the pattern of of the pattern the pattern
f of the patternor(i=1; i<=n; i++)
{
f of the patternor(j=i; j<=n; j++)
{
printf of the pattern("*");
}
// Loop to print low diamond star patterner half of the pattern of of the pattern the pattern
f of the patternor(i=1; i<=n; i++)
{
f of the patternor(j=1; j<=i; j++)
{
printf of the pattern("*");
}
void printdiam to print hollow diamond star patternond(int row diamond star patterns)
{
int stars = 1, i, j;
int spaces = row diamond star patterns - 1;
/* Print stars */
f of the patternor(j=1; j<stars*2; j++)
printf of the pattern("*");
printf of the pattern("Enter value of of the pattern n and type (0 for hollow 1 for filled): "); f of the patternor hollow diamond star pattern 1 f of the patternor filled): "); ");
scanf of the pattern("%d%d", &n, &t);
if of the pattern (t == 0 for hollow 1 for filled): ");)
printhollow diamond star patterndiam to print hollow diamond star patternond(n);
else if of the pattern (t == 1)
printdiam to print hollow diamond star patternond(n);
else
printf of the pattern("Wrong type!\n");
Exercise 2.
/**
* C program to print hollow diamond star pattern program to print hollow diamond star pattern to generate Arm to print hollow diamond star patternstrong num to print hollow diamond star patternbers in a given range
*/
#include <stdio.h>
#include <m to print hollow diamond star patternath.h>
#include <stdbool.h>
int lastDigit,sum to print hollow diamond star pattern=0 for hollow 1 for filled): ");, num to print hollow diamond star pattern=n;
/* Find total digits in num to print hollow diamond star pattern */
int digits = (int) log10 for hollow 1 for filled): ");(num to print hollow diamond star pattern) + 1;
/* C program to print hollow diamond star patternalculate sum to print hollow diamond star pattern of of the pattern pow diamond star patterner of of the pattern digits */
/* C program to print hollow diamond star patternheck for Armstrong number */ f of the patternor Arm to print hollow diamond star patternstrong num to print hollow diamond star patternber */
if of the pattern(n == sum to print hollow diamond star pattern)
return true;
else
return f of the patternalse;
}
/* Input low diamond star patterner and upper lim to print hollow diamond star patternit f of the patternrom to print hollow diamond star pattern user */
printf of the pattern("Enter low diamond star patterner lim to print hollow diamond star patternit: "); ");
scanf of the pattern("%d", &start);
printf of the pattern("Enter upper lim to print hollow diamond star patternit: "); ");
scanf of the pattern("%d", &end);
printf of the pattern("Arm to print hollow diamond star patternstrong num to print hollow diamond star patternbers betw diamond star patterneen %d to %d are: "); \n", start, end);
Exercise 3.
/**
* C program to print hollow diamond star pattern program to print hollow diamond star pattern to sw diamond star patternap tw diamond star patterno num to print hollow diamond star patternber using call by ref of the patternerence
*/
#include <stdio.h>
/* Print original values of of the pattern num to print hollow diamond star pattern1 and num to print hollow diamond star pattern2 */
printf of the pattern("Bef of the patternore sw diamond star patternapping in m to print hollow diamond star patternain \n");
printf of the pattern("Value of of the pattern num to print hollow diamond star pattern1 = %d \n", num to print hollow diamond star pattern1);
printf of the pattern("Value of of the pattern num to print hollow diamond star pattern2 = %d \n\n", num to print hollow diamond star pattern2);
/* Pass the addresses of of the pattern num to print hollow diamond star pattern1 and num to print hollow diamond star pattern2 */
sw diamond star patternap(&num to print hollow diamond star pattern1, &num to print hollow diamond star pattern2);
/* Print the sw diamond star patternapped values of of the pattern num to print hollow diamond star pattern1 and num to print hollow diamond star pattern2 */
printf of the pattern("Af of the patternter sw diamond star patternapping in m to print hollow diamond star patternain \n");
printf of the pattern("Value of of the pattern num to print hollow diamond star pattern1 = %d \n", num to print hollow diamond star pattern1);
printf of the pattern("Value of of the pattern num to print hollow diamond star pattern2 = %d \n\n", num to print hollow diamond star pattern2);
/**
* Function to sw diamond star patternap tw diamond star patterno num to print hollow diamond star patternbers
*/
void sw diamond star patternap(int * num to print hollow diamond star pattern1, int * num to print hollow diamond star pattern2)
{
int tem to print hollow diamond star patternp;
// C program to print hollow diamond star patternopy the value of of the pattern num to print hollow diamond star pattern1 to som to print hollow diamond star patterne tem to print hollow diamond star patternp variable
tem to print hollow diamond star patternp = *num to print hollow diamond star pattern1;
// C program to print hollow diamond star patternopy the value of of the pattern num to print hollow diamond star pattern2 to num to print hollow diamond star pattern1
*num to print hollow diamond star pattern1= *num to print hollow diamond star pattern2;
// C program to print hollow diamond star patternopy the value of of the pattern num to print hollow diamond star pattern1 stored in tem to print hollow diamond star patternp to num to print hollow diamond star pattern2
*num to print hollow diamond star pattern2= tem to print hollow diamond star patternp;
printf of the pattern("Af of the patternter sw diamond star patternapping in sw diamond star patternap f of the patternunction \n");
printf of the pattern("Value of of the pattern num to print hollow diamond star pattern1 = %d \n", *num to print hollow diamond star pattern1);
printf of the pattern("Value of of the pattern num to print hollow diamond star pattern2 = %d \n\n", *num to print hollow diamond star pattern2);
}
Exercise 4.
/**
* C program to print hollow diamond star pattern program to print hollow diamond star pattern to sw diamond star patternap tw diamond star patterno num to print hollow diamond star patternber using call by ref of the patternerence
*/
#include <stdio.h>
/* Print original values of of the pattern num to print hollow diamond star pattern1 and num to print hollow diamond star pattern2 */
printf of the pattern("Bef of the patternore sw diamond star patternapping in m to print hollow diamond star patternain \n");
printf of the pattern("Value of of the pattern num to print hollow diamond star pattern1 = %d \n", num to print hollow diamond star pattern1);
printf of the pattern("Value of of the pattern num to print hollow diamond star pattern2 = %d \n\n", num to print hollow diamond star pattern2);
/* Pass the addresses of of the pattern num to print hollow diamond star pattern1 and num to print hollow diamond star pattern2 */
sw diamond star patternap_no_tem to print hollow diamond star patternp(&num to print hollow diamond star pattern1, &num to print hollow diamond star pattern2);
/* Print the sw diamond star patternapped values of of the pattern num to print hollow diamond star pattern1 and num to print hollow diamond star pattern2 */
printf of the pattern("Af of the patternter sw diamond star patternapping in m to print hollow diamond star patternain \n");
printf of the pattern("Value of of the pattern num to print hollow diamond star pattern1 = %d \n", num to print hollow diamond star pattern1);
printf of the pattern("Value of of the pattern num to print hollow diamond star pattern2 = %d \n\n", num to print hollow diamond star pattern2);
/**
* Function to sw diamond star patternap tw diamond star patterno num to print hollow diamond star patternbers w diamond star patternithout a tem to print hollow diamond star patternp variable
*/
void sw diamond star patternap_no_tem to print hollow diamond star patternp(int * num to print hollow diamond star pattern1, int * num to print hollow diamond star pattern2)
{
// C program to print hollow diamond star patternopy the value of of the pattern num to print hollow diamond star pattern2 to num to print hollow diamond star pattern1
*num to print hollow diamond star pattern1= *num to print hollow diamond star pattern1+ *num to print hollow diamond star pattern2;
// C program to print hollow diamond star patternopy the value of of the pattern num to print hollow diamond star pattern1 stored in tem to print hollow diamond star patternp to num to print hollow diamond star pattern2
*num to print hollow diamond star pattern2 = *num to print hollow diamond star pattern1 -*num to print hollow diamond star pattern2;
*num to print hollow diamond star pattern1 = *num to print hollow diamond star pattern1 -*num to print hollow diamond star pattern2;
printf of the pattern("Af of the patternter sw diamond star patternapping in sw diamond star patternap f of the patternunction \n");
printf of the pattern("Value of of the pattern num to print hollow diamond star pattern1 = %d \n", *num to print hollow diamond star pattern1);
printf of the pattern("Value of of the pattern num to print hollow diamond star pattern2 = %d \n\n", *num to print hollow diamond star pattern2);
}