Quiz 2 PF
Quiz 2 PF
Question 1:
(Diamond Printing Program)Write a program that prints the
following diamond shape. You may use printf statements that print either a
single asterisk (*) or asingle blank. Maximize your use of repetition (with
nested for statements) and minimize the number of printf statements.
Answer:
Program Code:
// c program to print a diamond shape
#include<stdio.h>
int main()
{
int n, s, i, j;
printf("Enter number of rows: ");
scanf("%d",&n);
for(i = 0; i <= n; i++)
{
for(s = n; s > i; s--)
printf(" ");
for(j=0; j<i; j++)
printf("* ");
printf("\n");
}
for(i = 1; i < n; i++)
{
for(s = 0; s < i; s++)
printf(" ");
Comsat University Abbottabad Department of BSE-2C
printf("\n");
}
return 0;
}
Output:
Enter the 10 rows that show the diamond shape.
Question 2:
Write a program that gets a character from the user, using call by
value and by reference, print all the characters from the read characters to z
(Either entered in small or capital), also print the result in main how many
characters are printed from the character read. Implement this program by
using both the calling methods...
Comsat University Abbottabad Department of BSE-2C
1. Call by value
2. Call by reference.
Answer:
Program Code:
#include <stdio.h>
int main() {
char chr, chr3, loop1;
int number=0;
} else
{
number = func_upper(&chr3);
}
Comsat University Abbottabad Department of BSE-2C
Output:
1st output:
2nd output:
Comsat University Abbottabad Department of BSE-2C
The End