Skip to content

MyUstaadG

Learn to Serve

  • Computer Science
    • Software
    • Computer Tips
    • Coding
      • Conditional Structures Exercises
      • Loops Exercises
      • Arrays Exercises
      • Python Exercises
    • Microsoft Office
      • MS Excel
      • MS Word
  • Videos
    • Funny Videos
    • Health and Fitness Videos
    • PUBG Videos
    • Technology Videos
  • News
  • Funny
  • Memes
  • Playwright Tutorials
  • Tutorials
  • Toggle search form

Write a program that initializes roll numbers and marks of different subjects in a two-dimensional array.

Posted on October 17, 2021 By myustaadg.com
Spread the love

Write a program that initializes roll numbers and marks of different subjects in two-dimensional array. The roll numbers should be in first column and marks of different subjects should be in other columns such as:
1 55 78 95 75
2 54 85 62 85
3 58 81 85 75
4 60 82 74 75
5 45 72 25 74
The program should read the 2-D array, compute the total marks of each student and store the result in the last column.

So let’s Write Code:

Introduction to C++ Programming | Download and Install Dev C++ Compiler

Let’s build logic First:

Algorithm for code:

  • Step 1: Start
  • Step 2: Declare an 2D array tab1.
  • Step 3: Check if r< =4 then ask the user to enter the rollno.
  • Step 4: Check if c < 4 then ask the user to enter the subject mark.
  • Step 5: Repeat Step 4 until c<4, if is not c<4 then goto step 3.
  • Step 6: Print results.
  • Step 7: End Program

Code:

Write a program that initializes roll numbers and marks of different subjects in a two-dimensional array.

#include<iostream>
using namespace std;
main()
{
int tab1[5][6], r, c, s;
r = 0;
while(r<=4)
{
c = 0;
s = 0;
cout<<"Enter record # "<<r+1<<endl;
cout<<"Enter roll number ? ";
cin>>tab1[r][c];
while(c<4)
{
c = c + 1;
cout<<"Enter marks of subject "<<c<<" ? ";
cin>>tab1[r][c];
s = s + tab1[r][c];
}
c = c + 1;
tab1[r][c] = s;
r++;
}
cout<<"\nRecords of students:" <<endl;
cout<<"Roll#\tSub1\tSub2\tSub3\tSub4\tTotal Marks"<<endl;
for(r = 0; r<=4; r++)
{
for(c = 0; c<=5; c++)
cout<<tab1[r][c]<<"\t";
cout<<endl;
}
}

Hope You will learn Something. Happy Coding.

Visit my YouTube Channel as Well😇 https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4

Click on the below Links for more Programming Exercises:

Conditional Structure Exercises: 👉https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/

Array Exercises: 👉https://myustaadg.com/category/programming-exercises/arrays-exercises/

Arrays Exercises, Programming Exercises Tags:array declaration in c++, Array Exercises, Array exercises in C++, Arrays, arrays codes, Arrays exercises, Arrays in C++, Arrays in C++ Programming with examples, Arrays in Programming, Arrays with example, C++ array: declare, C++ Arrays with examples, Creating and Using Arrays, how do you initialize an array in c++, how to display elements in 2D array, how to display vales in 2D array, how to initialize 2D arrays, how to use 2D array, how to use two dimension array, initialize, Two dimensional (2D) arrays in C ++ programming with example, two dimenstion array in c++, Write a program that initializes roll numbers and marks of different subjects in a two-dimensional array.

Post navigation

Previous Post: Write a program that initializes values in a one-dimensional array and Calculate the sum of an array using function.
Next Post: Write a program that uses three arrays ‘roll_no’, ‘name’ and ‘marks’. It inputs roll numbers, names and marks of 10 students into these arrays. It searches the highest marks.

More Related Articles

Write a program that initializes data into a one-dimensional array. Search value using binary search. Arrays Exercises
Write a program that inputs ages of different persons in an array and counts the number of persons that have ages between 65 and 80. Arrays Exercises
Write a program that asks the user their annual income and shows on the screen the tax rate that corresponds to them | Python Programming Programming Exercises
Write a function, and a program to test it, that will place a zero in each element of array passed to it from the calling program. Arrays Exercises
Write a program that reads a positive integer, , entered by the user and then displays on the screen the sum of all integers from 1 to . The sum of the positive first integers can be calculated as follows: Sum =n(n+1)/2 | python Programming Programming Exercises
Write a program that inputs real values into float type array. It reads the value of each element of float type array and assigns to int type array. Arrays Exercises

Copyright © 2022 MyUstaadG.

Powered by PressBook Blog WordPress theme