Евгений
Gilded
Евгений
It should indent your code
Gilded
Евгений
did nt work
I see. In my visual studio 2022 works
Anonymous
admin
// Decimal to Hexa Conversion
#include <bits/stdc++.h>
using namespace std;
int dec2hex(int dec)
{
// dec=5386
int a, b, ans;
int i = 0;
string str[10];
char ch;
while (a > 0)
{
a = dec / 16; // 336,21,
b = dec % 16; // 10,0
str[i] = b;
dec = dec / 16; // 336
i++;
}
int x = str[10].size();
for (int j = x - 1; j >= 0; j--)
{
cout<<str[j];
}
}
int main()
{
int dec;
cin >> dec;
cout << dec2hex(dec) << endl;
}
admin
code is not working... plz help anyone.
Евгений
Danya🔥
Ludovic 'Archivist'
Why is that?
Because if you want to use the native APIs or make drivers or use DirectX comfortably it is the choice on Windows
Anonymous
admin
// Decimal to Hexa Conversion
#include <bits/stdc++.h>
using namespace std;
int dec2hex(int dec)
{
// dec=5386
int a, b, ans;
int i = 0;
string str[10];
char ch;
while (a > 0)
{
a = dec / 16; // 336,21,
b = dec % 16; // 10,0
str[i] = b;
dec = dec / 16; // 336
i++;
}
int x = str[10].size();
//print reverse the number
for (int j = x - 1; j >= 0; j--)
{
cout<<str[j];
}
}
int main()
{
int dec;
cin >> dec;
dec2hex(dec) ;
}
admin
code is not working... plz help anyone.
Anonymous
Why did declare out of function?
Anonymous
Danya🔥
Danya🔥
Ludovic 'Archivist'
Anonymous
Anonymous
#include <stdio.h>
int dost();
int main()
{
dost();
return 0;
}
int dost() {
int a, b,c;
printf("Enter a number: ");
scanf("%d", &a);
printf("Enter a number: ");
scanf("%d", &b);
c = a+b;
printf ("The sum is : %d", c);
return c;
Anonymous
This is the right code
Marcio
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Hi guys, so I was given the task to write a software that takes nBytes random bytes from /dev/random device (let it be fd2, after a read only open invocation), and writes it on another file opened in write, let it be fd1. This is quite easy, yet there's a complication: fd1 must be filled with shorts (so 2 bytes) . My solution was to read 2 bytes per time (untill I get to nBytes), thus filling a buffer like the one following:
char buff[2];
and then writing those 2 bytes on the new file. The question is about what happens while writing: so, I have those 2 bytes written in memory, but will they be considered as a short? Or just two random bytes separated? In class we were only told that a short is 2 bytes, nothing further about memory representation, so I want to make sure that the two bytes I write really are a short, and the next two bytes I write are considered as another individual short. Thanks!
Following, the part of the code that does the read from fd2 -> write to fd1 job. I'll quickly resume who's who:
1) fd1 is the destination file (the one I want to write on);
2) fd2 is the source file (the one I opened in reading to get the bytes from);
3) nBytes is the number of bytes (given by the user, I made sure at the beginning of the code that it always is a multiple of 16) the users wants to be written on the file. Notice: not the number of shorts, but the number of the bytes. For istance, if the user wants 2^15 bytes, then, given the fact that a short is 2 bytes, I shall write 2^14 shorts;
4) counter is, as the name suggests, a counter I use in order to understand how many bytes were already copied in fd1.
// Rest of the code was not posted because it is not relevant:
char buff[2];
unsigned long int counter= 0;
do{
if(read(fd2, buff, counter) != 2){
printf("Error in reading!\n");
exit(1);
}
if(write(fd1,buff, 2) != 2){
printf("Error in writing!\n");
exit(1);
}
counter += 2;
} while (nBytes - counter >= 0);
Anonymous
Hi guys which youtube channel is good for c language
Nomid Íkorni-Sciurus
Anonymous
A channel?
Nomid Íkorni-Sciurus
A channel?
sorry, it had to be a joke, I couldn't resist.
youtube and learning do not go well together in this field
Nomid Íkorni-Sciurus
what I meant is that you should look for better resources on the web
redfox
can anyone explain templates to me
Anonymous
Nomid Íkorni-Sciurus
can anyone explain templates to me
Imagine you have a Box
a Box can contain anything
so how can you say two Boxes are equal if they're content is unknown?
one thing the templates are used for, is specifying this kind of relationship so that Box<A> and Box<B> will be different but Box<A> and Box<A> will be equal
Nomid Íkorni-Sciurus
this is just one of the applications though.
they're a vast concept I advice you to dig deeper
Faramarz
Hi can you help me to figure out how to avoid memory leak when I'm using malloc?
Thank you
KBS
$ameer
Can someone please guide me pops Nasasity
Anonymous
Codeblocks
CodeBlocks is an IDE , not just a compiler
Nomid Íkorni-Sciurus
Anonymous
Precisely it is not
Anshul
the logic that i am applying is: i am keeping an iterator to start of vector,
whenever peek is called i just return what's pointed by iterator.
for next function, i store what is pointed by iterator, increment the iterator to the next step and then return the stored value.
and for hasnext function, i check if it-(starting address of vector) is greater than or equal to vector size, if yes there are no more elements avlbl return false else return true
Евгений
Anshul
CALVIN
How to filter out a record of a file maybe using one variable....... But let me share my code first where I attempted this....
Natanim
im trying to write the output of a code but its hard unless i show it by an image
i have a question about it
Natanim
its when outputting a number pattern in a diamond form, but the pattern should look something like this»
> 3
232
12321
232
3
Natanim
its when outputting a number pattern in a diamond form, but the pattern should look something like this»
> 3
232
12321
232
3
/*this code outputs from the outside in but im having trouble shifting it so it could output the above one, i need some help here*/
#include <iostream>
using namespace std;
int main() {
int i, j, k, l, rows;
cout << "Enter Diamond Number Pattern Row = "; cin >> rows;
cout << "Diamond Number Pattern\n";
for(i = 1; i <= rows; i++) {
for(j = 1; j <= rows - i; j++)
{ cout << " "; }
for(k = i; k >= 1; k--)
{ cout << k; }
for(l = 2; l <= i; l++)
{ cout << l; }
cout << "\n"; }
for(i = rows - 1; i > 0; i--)
{ for(j = 1; j <= rows - i; j++) { cout << " "; }
for(k = i; k >= 1; k--)
{ cout << k; }
for(l = 2; l <= i; l++)
{ cout << l; }
cout << "\n"; }
return 0;
}
Pita
#include <iostream>
using namespace std;
main(){
int data, jumlah, cacah;
jumlah = 0;
data = 0;
cacah = 0;
while (data != -1)
{
cout << "Masukkan data angka : ";
cin >> data; jumlah += data; cacah++;
}
cout << " Jumlah data adalah : " << jumlah << endl;
cout << "Rata-rata :" << jumlah/cacah;
}
三体183号
You are too voluptuous
Pita
三体183号
I used to be satisfied with learning for two hours, but now it's painful not to learn for two hours
三体183号
三体183号
You can see their changes every time
Anshul
Anshul
Anonymous
Anshul
Anonymous
The calling code could be like
vec<int> tmp;
PeekingIterator it(tmp);
tmp.push_back(.......);
Anshul
Anshul
Thanks I understood this
And while going through solution to this problem I came across this way to write peek
Return (*this).next
Anshul
int peek()
{
return Iterator(*this).next();
}
How does this work?
Anonymous
int peek()
{
return Iterator(*this).next();
}
How does this work?
The way it is supposed to work. Though it is a tad inefficient but. You can implement it a bit more directly.
Iterator(*this) creates a new iterator that shares state with your current iterator pointed to by this. You call next on it which returns the element to be peeked at. The temporary is destroyed after that. The original object pointed at by "this pointer" is not changed.
Anshul
I'm trying to understand this
Anshul
Anshul
Anonymous
b and a both are pointing to same memory or a deep copy is created here 😐
That depends on how Iterator class is implemented. In all likelihood they will just have copies of the state they are in i.e. the element they are pointing at.
So calling next on on one iterator does not affect the state on the other iterator.
And you shouldn't be worried about it either. The question says that Iterator has a copy constructor and so you can assume it is implemented correctly and just use it
Anshul
I am able to understand it now
Thank you so much
Anshul
Anshul
klimi
(tho if you are working with int you don't have to worry about anything as it is such small size)