READ and FOLLOW all directions (post a screenshot of the code if possible and pr
ID: 3888090 • Letter: R
Question
READ and FOLLOW all directions
(post a screenshot of the code if possible and proof that the program can run)
C++ code language, using FOR and WHILE loops, and ARRAY to solve
CLEAN CODE IS A MUST! WRITE FOR READABILITY
1. Write a program that converts decimal number to hexadecimal
1a) Write a program using nested loops that asks the user to enter a value for the number of rows to display. It should display that many rows as asteriks with 1 asterik in the first row, 2 in the second row, and so on. However the last asterik in each row should be aligned (PRECEDED BY SPACES) (DO NOT USE SET PRECISION)
Explanation / Answer
1. Program that converts decimal number to hexadecimal
Code in c++:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
long int decnum, rem, quot;
char hexdecnum[100];
int i=1, j, temp;
cout<<"Enter any decimal number : ";
cin>>decnum;
quot=decnum;
while(quot!=0)
{
temp=quot%16;
if(temp<10)
{
temp=temp+48;
}
else
{
temp=temp+55;
}
hexdecnum[i++]=temp;
quot=quot/16;
}
cout<<"Equivalent hexadecimal value of "<<decnum<<" is : ";
for(j=i-1; j>0; j--)
{
cout<<hexdecnum[j];
}
getch();
}
1a)
#include <iostream>
using namespace std;
int main()
{
int rows = 0;
int less = 1;
cout << "Enter number of rows: ";
cin >> rows;
for(int i=0; i < rows; i++)
{
for(int d=0; d < (rows - less); d++)
cout << ".";
for(int a=0; a < less; a++)
cout << "*";
cout << endl;
less++;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.