Question

3. Write a program (in C or in any other language) that prints the first 64 rows of the Pascal triangle modulo 2. Specifically, the entry in row nand column k of the printout should be 0 if (K) is even, and 1 otherwise. Submit both the program and the printout it produces.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The following C code gives you the required functionality:

#include <stdio.h>
void printPascal(int n);
int main()
{
int n = 64;
printPascal(n);
return 0;
}//end of main function

void printPascal(int n)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
printf("%d ",bin_coef(i,j));
printf("\n");
}
}//end of printPascal function

int bin_coef(int n, int k)
{
long long int res = 1,i;
if(k>(n-k))
k = n-k;
for(i=0;i<k;i++)
{
res = (res * (n-i))%2;
res = res / (i+1);
}
return res%2;
}//end of bin_coef function

Output:

Hope it helps, feels free to comment in case of any query.

Add a comment
Know the answer?
Add Answer to:
Write a program (in C or in any other language) that prints the first 64 rows...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write this python program 4. Pascal Triangle. Write a program pascal.py that builds and prints a...

    write this python program 4. Pascal Triangle. Write a program pascal.py that builds and prints a two-dimensional list (a list of lists) a such that a[n][k contains the coefficient of the k-th term in the binomial expansion of (ty) These coefficients can be organized in a triangle, famously known as Pascals triangle. Every row in the triangle may be computed from the previous row by adding adjacent pairs of values together. Below is a sample invocation of the program s...

  • Write a program to place eight queens on an 8 x 8 chessboard in such a...

    Write a program to place eight queens on an 8 x 8 chessboard in such a way that one queen is to be in each row. A program will use 2 DIMENIONAL array x[r][c] to do this configuration. If x[r] has value c, then in row r there is a queen in column c. Write a program that asks a user to enter the columns that contain queens in the 8 rows. The program then places the queens in these...

  • In Any Language write a function to loop through a csv file (10 rows no headers)...

    In Any Language write a function to loop through a csv file (10 rows no headers) and pull out the data from the 3rd column (string). Create one string with those values separated by commas in arranged in alphabetical order by the first letter (example: “Amazon, Aaron, Base, …..”, Amazon and Aaron do not need to be reversed). It can be assumed the csv file is already read into a variable. Please provide comments.

  • *Answer must be in C* Write a complete program as follows (declare any necessary variables): Create...

    *Answer must be in C* Write a complete program as follows (declare any necessary variables): Create an array of doubles named “hummus” with 2 rows and 300 columns. Initialize all array elements to zero. Write a loop that will repeatedly ask the user to enter a value and store it in the first row of the array (do not overwrite previously entered values) until the whole first row is populated with the user input. (hint the loop should have the...

  • it's in C programming language 3. Write a program to find out if the first two...

    it's in C programming language 3. Write a program to find out if the first two bits of an input hex number is 11and will print "the first two bits are ones" 4- Write a program that will perform the following: Check the first two numbers of an input data if they are 11 and will print "open door 1" if so, otherwise Check the last two bits of that number if they are 11 and print" Open door 2...

  • Write a Program in C language for: 1. Create a C program to read 7 integers...

    Write a Program in C language for: 1. Create a C program to read 7 integers and store them in an array. Next, the program is to check if the array is symmetric, that is if the first element is equal to the last one, the value of the second one is equal to the value of the last but one, and so on. Since the middle element is not compared with another element, this would not affect the symmetry...

  • use scheme program The following pattern of numbers is called Pascal's triangle. The numbers at the...

    use scheme program The following pattern of numbers is called Pascal's triangle. The numbers at the edge of the triangle are all 1, and each number inside the triangle is the sum of the two numbers above it. (pascals 0 0) → 1 (pascals 2 0) → 1 (pascals 2 1) → 2 (pascals 4 2) → 6 (printTriangle 5) 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 [5 marks] Write a procedure...

  • HELP NEEDED in C++ (preferred) or any other language Write a simple program where you create...

    HELP NEEDED in C++ (preferred) or any other language Write a simple program where you create an array of single byte characters. Make the array 100 bytes long. In C this would be an array of char. Use pointers and casting to put INTEGER (4 byte) and CHARACTER (1 byte) data into the array and pull it out. Make sure you can access both character and integer data at any location in the array. Read data from a text file....

  • I am having trouble figuring out why my program will not make any columns, just rows....

    I am having trouble figuring out why my program will not make any columns, just rows. I need to display a square. The instructions are provided below. (This for my C++ class) Write a program that displays a square. Ask the user for the square’s size. Only accept positive integer numbers (meaning choose a data type that holds positive integer values). The size the user gives you will determine the length and width of the square. The program should then...

  • Write a C++ program to simulate a stream path. In this problem you can make the...

    Write a C++ program to simulate a stream path. In this problem you can make the following assumptions 1. The elevation grid will be a n row, m column grid of integers, where n and m are constant. 2. Once the stream origin location is specified, then the stream flows to whichever of the four adjacent locations in the grid represents the largest descent. 3. If more than one of the adjacent locations have the largest descent, then the water...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT