printin(valip op+val2 resuit) , PROGRAMMING QUESTIONS (45 marks in total with 15
ID: 3736598 • Letter: P
Question
printin(valip op+val2 resuit) , PROGRAMMING QUESTIONS (45 marks in total with 15 Section marks each) 1. Write a program with a method that displays an n-by-n matrix using the following header: public static void printMatrix(int n) Each element is either 0 or I. which is generated randomly. Write s test program thes prints 3-by-3 matrix that may look like this: 010 2. Write a program called HandInput, to read user input line by line from console, and save all the input contents into a file "user.txt", if user input "endiend", the program ends (without saving endfend into the file). If the file is already there, the program should prompt user "The file exits!" and terminate. 3. Write a program to perform add, subtract, multiply, and divide operations, figure shown as below Question2 in Tutorial 20 Number 2 2 Result 7e Number 1 Add Substract ultiply DrideExplanation / Answer
#include<stdio.h>
#include <time.h>
#include<stdlib.h>
//method to print nxn matrix...of 0,1 's randomly.
void printMatrix(int n)
{
int i,j,r;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
r = rand()%2;
printf("%d ",r);
}
printf(" ");
}
}
int main()
{
//printing 3x3 matrix
printMatrix(3);
return 0;
}
output:
1 1 0
0 1 0
0 0 0
Process exited normally.
Press any key to continue . . .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.