Skip to main content

Posts

Showing posts from April, 2018

Program to multiply two matrices

Hello, I hope you are able to add two matrices as per the previous post. Now, we will go a step further and multiply the matrices. To multiply matrices, it should satisfy the basic condition i.e. number of columns in the first matrix should be equal to the number of rows in the second matrix. Let's try it out. Don't forget to post the screenshot of the output in the comment section. #include <stdio.h> #include<conio.h> void main() {     int mat1[10][10], mat2[10][10], mul[10][10], r1, c1, r2, c2, i, j, k;     clrscr();     printf("Enter rows and column for first matrix: \n");     scanf("%d %d", &r1, &c1);     printf("Enter rows and column for second matrix: \n");     scanf("%d %d",&r2, &c2);     // Column of first matrix should be equal to column of second matrix and     while (c1 != r2)     { printf("Error! column of first matrix ...

Lab Sessions

Hello, Click on Respective Link to Complete the Assignment. Note: You can submit the response only once.  Lab Assignment - B1 Lab Assignment - B2 Lab Assignment - B3 Lab Assignment - A3

Lex - YACC

Try your hands on Lex Tools using C. Store the following code with desired filename having extension .l (dot L) Use Ubuntu operating system for running the code at ease. Code to check whether given number is Positive or Negative . %{ int p=0, n=0,pf=0,nf=0; %} %% [0-9]+ {p++;} -[0-9]+ {n++;} [0-9]*.[0-9]+ {pf++;} -[0-9]*.[0-9]+ {nf++;} %% main() { printf("Enter the data\t"); yylex(); printf("The positive Number %d \n",p); printf("The Positive Float %d \n",pf); printf("The Negative Number %d \n",n); printf("The Negative Float %d \n",nf); } Commands in terminal- lex filename .l gcc lex.yy.c -ll ./a.out

Program to add two square matrices

Hello, Now we will code for addition of matrices. To do that, we have to develop a logic and step by step you should proceed towards the execution of the program. Steps involved in the execution are:  Code for getting dimensions and getting the elements of both the matrix. You are preferably using for loops Print both the matrices on the console Add matrices and print them on the console screen. You are highly encouraged to post the screenshot of the output in the comment section. #include<stdio.h> #include<conio.h> void main() { int i,j,r1,c1,mat1[10][10],mat2[10][10],sum[10][10]; clrscr(); printf("Enter dimensions of a square matrix \n"); scanf("%d %d",&r1,&c1); printf("Enter elements of First Matrix:\n"); for (i = 0; i<r1;i++) { for (j=0;j<c1;j++) { printf("Enter mat1[%d][%d]=",i,j); scanf("%d",&mat1[i][j]); } } printf("Enter elements of Second Matrix:\n"); fo...

Macro Pass 1 and Pass 2

Hello, I presumed that you are aware of various databases needed for the Pass 1 &2. Please provide a following with the input file macroinput.txt I request you to post the screenshot of the output. import java.util.*; import java.io.*; class MntTuple { String name; int index; MntTuple(String s, int i) { name = s; index = i; } public String toString() { return("[" + name + ", " + index + "]"); } } class MacroProcessor { static List<MntTuple> mnt; static List<String> mdt; static int mntc; static int mdtc; static int mdtp; static BufferedReader input; static List<List <String>> ala; static Map<String, Integer> ala_macro_binding; public static void main(String args[]) throws Exception { initializeTables(); System.out.println("===== PASS 1 =====\n"); pass1(); System.out.println("\n===== PASS 2 =====\n"); pass2(); } static void pas...

Absolute Loader

Hello, We will now code for absolute loader scheme. For that, you have to give input code which is stored in SAMPLE_TEC.TXT When asked for Object File Name, please give the name stored in file SAMPLE_TEC.TXT. (i.e. TECPGM) You are encouraged to post the screenshot of the output of the program in comment section. import java.io.*; import java.io.RandomAccessFile.*; import java.lang.*; class absolute { String s,prog_name,obj_name,staddr; long d=0; int i,j,staddr1; //char[] staddr=new char[30]; void display() { try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("\nEnter the program name : "); prog_name=br.readLine(); File f=new File("E:/sample_tec.txt"); RandomAccessFile fr=new RandomAccessFile(f,"r"); long size=fr.length(); if(d<size) { s=fr.readLine(); if(s.charAt(0)=='H') { obj_name=s.substring(2,8); System.out.println("Object Program Name From File : "+obj...