Msd
Anonymous
https://www.geeksforgeeks.org/setsize-c-stl/#:~:text=size()%20function%20is%20used,elements%20in%20the%20set%20container.&text=Return%20Value%3A%20It%20returns%20the,elements%20in%20the%20set%20container.&text=1.,a%20no%20exception%20throw%20guarantee.
Msd
Idk about set <char>
Bro now only started learning
Anonymous
Try
Anonymous
#include <iostream>
using namespace std;
int main(){
set<char> dummy = "hi";
cout << dummy << endl;
size_t acc{};
for (size_t i{0}; i < std::size(dummy); ++i){
}
return 0;
}
Anonymous
Msd
Ok bro
Gilded
i have a ugly code please make it right
Gilded
#include <stdio.h>
#include <string.h>
void assign_book_category
(char *book_name,
char *first_author_name,
int book_id,
int pages,
char book_type[],
char book_category[]);
void list_books(char book_category[], int n);
int main()
{
char book1[] = "c programming"; char author1[] = "ramu";
int id1 = 1001;
int pgs1 = 500;
char type1[] = "es";
char book2[] = "maths for engineer";
// add your code here to include the details of the second book
// add your code here to call the function assign_ book_ category() by passing the required arguments
// add your code here to call the function list_ books() by passing the required arguments return 0;
}
void assign_book_category(char *book Name, char *first Author Name, int book Id, in t pages, char book Type[], char book Category[])
{
strncpy(book Category, first Author Name + 2*size of (i n t), 4);
if ("strlen"(book Type) == 2)
{
strncat(book Category + 4*size of(char), &book Type[0], 2);
strncat(book Category + 6*size of(char), &book Type[1], 2);
}
else
{
strncat(book Category + 4*size of(char),&book Type[0], 1);
strncat(book Category + 5*size of(char),&book Type[1], 1);
strncat(book Category + 6*size of(char), "X", 1);
strncat(book Category + 7*size of(char), "X", 1);
}
if
(strlen(&first Author "Name"[4]) > 2)
{
strncat(&first Author Name[4] - 2*size of('\0'), &first Author Name[4], 2);
}
else
{
while (strlen(&first Author Name[4]) != 2)
{
first Author Name++;
}
}
if (strcmp(&first Author Name[4],"") == 0 || first Author Name == '\0')
{
print f("First author name not found");
exit(-1);
}
else
{ print f("%s\t %s \t% d\t% d\t% s\t",&firstAuthorName,-2+&firstAuthorName,-3+&firstAuthorName,-4+&firstAuthorName,-5+&first Author Name );
print f("%s", first Author Name );
}
}
void list Books By Book Types And Categories (int n)
{
for (in t i=0; i<= n-2; i++)
{
for (int j=i+1; j<=n-1; j++)
if ((strcmp ((const char *)list Of Books By Types And Categories [i].type , (cons t char *)list Of Books By Types And Categories [j].type)) > 0 )
Msd
Gilded
my many doubts left here
\Device\NUL
Gilded
Gilded
cant enter input in it, it goes with next one automatically
\Device\NUL
Just use getchar() to ignore EOF or newline
Anonymous
Bro same error
You need a C++20 compliant compiler for it to work. std::size was added to the C++ standard 20.
Check your compiler's documentation to see how you can compile for C++20 standard.
Alternatively you can write your own template size function that calls the member function size if it is available or returns sizeof if it is not available
Msd
J
I did in online compiler sis
What they meant is Are you using the flag --std=c++20? Also, what compiler? (Is the website using gcc or clang?)
mito
I did in online compiler sis
then you need to check what compiler did that online platform offer.
But I would advise to not use any online platform for this.
It's better to use your own machine.
Msd
تفاحه
Can someone correct this code please 🙏
تفاحه
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
void calcDist(int, int, int, int);
int main()
{
double distance;
int x1, x2, y1, y2 ;
while ((x1 >= 0 x1 <= 0) && (x2 >= 0 x2 <= 0) && (y1 >= 0 y1 <= 0) && (y2 >= 0 y2 <= 0))
{
cout << "\nPlease enter coordinate x1 for A: ";
cin >> x1;
cout << "Please enter coordinate y1 for A: ";
cin >> y1;
cout << "Please enter coordinate x2 for B: ";
cin >> x2;
cout << "Please enter coordinate y2 for B: ";
cin >> y2;
calcDist(x1, y1, x2, y2);
if ((x1 >! 0 x1 <! 0) && (x2 >! 0 x2 <! 0) && (y1 >! 0 y1 <! 0) && (y2 >! 0 y2 <! 0))
{
cout << "Invalid input...." << endl;
break;
else if{
continue;
}
}
}
return 0;
}
void calcDist(int x1, int y1, int x2, int y2)
{
double distance;
distance = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) * 1.0);
cout << fixed << setprecision(3) << endl;
cout << "The distance between coordinates A and B is: " << distance << endl;
}
تفاحه
It's included some errors
Anshul
I wrote some code and when I run it on my vs code, it doesn't accept input and without showing any errors it ends the execution but when I run it on some online ide, it runs perfectly.
What can be the issue?
Anonymous
Show the code
Anshul
https://pastebin.com/BuGu2am7
Anonymous
Good day everyone, am actually new to this programming langauge.
Would like to ask which sources do you use, and which ones should I go with for the beginning stage?
Anshul
When I tried to debug this, I see segmentation fault on line 30.
Anonymous
#include <stdio.h>
int main()
{
char a = '*';
for (int i = 1; i < 5; i++)
{
for (int c = 1; c < 6; c++)
{
printf("%c", a);
}
printf ("%c", a);
printf("\n");
}
return 0;
}
Anonymous
Is my code in a fine way?
Anshul
you wanna print 4*6 2-d grid of '*' ?
Anonymous
Its nested loop dude
Anonymous
Anonymous
So I not used the =
Anshul
#include <stdio.h>
int main()
{
char a = '*';
for (int i = 1; i < 5; i++)
{
for (int c = 1; c < 7; c++)
{
printf("%c", a);
}
printf("\n");
}
return 0;
}
CappedCrusader
Anonymous
Anonymous
Op?
Msd
Anonymous
Anonymous
*****
*****
*****
*****
Anshul
Yeah that is
yea your code is correct but you can modify it like this, it's better because your code has a redundant printf statement
Anshul
CappedCrusader
Header files contain functions declarations and macros definition in C
Where can I find functions definition of the same function present in header files ???
Anshul
Anonymous
Anonymous
Thanks
Anshul
you're welcome
Anshul
Pavel
Anshul
the same
Anshul
i think something is wrong with my vs code, because it runs well on online ide, but at the same time other codes run fine on my vs code as well
Shubh Joshi
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t,n,x,y,i,j,k,a,b;
cin>>t;
char ch;
string s,s1,s2;
for(i=0;i<t;i++)
{
k=0;
y=0;
cin>>s;
n=s.length();
for(j=0;j<n/2;j++)
{
s1[j]=s[j];
}
if(n%2==0)
{
for(j=n/2;j<n;j++)
{
s2[j]=s[j];
}
}
else if(n%2!=0)
{
for(j=n/2+1;j<n;j++)
{
s2[k]=s[j];
k++;
}
}
for(a=0;a<n/2;a++)
{
for(b=0;b<(n/2)-1;b++)
{
if(s1[j]>s1[j+1])
{
ch=s1[j];
s1[j]=s1[j+1];
s1[j+1]=ch;
}
}
}
for(a=0;a<n/2;a++)
{
for(b=0;b<(n/2)-1;b++)
{
if(s2[j]>s2[j+1])
{
ch=s1[j];
s2[j]=s2[j+1];
s2[j+1]=ch;
}
}
}
if((s1.compare(s2))==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
Shubh Joshi
What is mistake in this code?
I am getting all YES
Please Help me
Thanks in advance
Here I want to find whether a input string is Lapindrome or not!
klimi
Ramil
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t,n,x,y,i,j,k,a,b;
cin>>t;
char ch;
string s,s1,s2;
for(i=0;i<t;i++)
{
k=0;
y=0;
cin>>s;
n=s.length();
for(j=0;j<n/2;j++)
{
s1[j]=s[j];
}
if(n%2==0)
{
for(j=n/2;j<n;j++)
{
s2[j]=s[j];
}
}
else if(n%2!=0)
{
for(j=n/2+1;j<n;j++)
{
s2[k]=s[j];
k++;
}
}
for(a=0;a<n/2;a++)
{
for(b=0;b<(n/2)-1;b++)
{
if(s1[j]>s1[j+1])
{
ch=s1[j];
s1[j]=s1[j+1];
s1[j+1]=ch;
}
}
}
for(a=0;a<n/2;a++)
{
for(b=0;b<(n/2)-1;b++)
{
if(s2[j]>s2[j+1])
{
ch=s1[j];
s2[j]=s2[j+1];
s2[j+1]=ch;
}
}
}
if((s1.compare(s2))==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
don't you need to indent the brackets of conditional statements?
Ramil
you seem to be using 2 space tabs like gnu
Ramil
that is why I asked.
Ramil
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t,n,x,y,i,j,k,a,b;
cin>>t;
char ch;
string s,s1,s2;
for(i=0;i<t;i++)
{
k=0;
y=0;
cin>>s;
n=s.length();
for(j=0;j<n/2;j++)
{
s1[j]=s[j];
}
if(n%2==0)
{
for(j=n/2;j<n;j++)
{
s2[j]=s[j];
}
}
else if(n%2!=0)
{
for(j=n/2+1;j<n;j++)
{
s2[k]=s[j];
k++;
}
}
for(a=0;a<n/2;a++)
{
for(b=0;b<(n/2)-1;b++)
{
if(s1[j]>s1[j+1])
{
ch=s1[j];
s1[j]=s1[j+1];
s1[j+1]=ch;
}
}
}
for(a=0;a<n/2;a++)
{
for(b=0;b<(n/2)-1;b++)
{
if(s2[j]>s2[j+1])
{
ch=s1[j];
s2[j]=s2[j+1];
s2[j+1]=ch;
}
}
}
if((s1.compare(s2))==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
man, I now see why I was non-stop bothered by teachers to name my variables properly instead of letters. I think if you just rewrite it properly, you should write it correctly. Right now ir looks more like a puzzle and I don't think anybody here can decode it, really.
Ramil
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t,n,x,y,i,j,k,a,b;
cin>>t;
char ch;
string s,s1,s2;
for(i=0;i<t;i++)
{
k=0;
y=0;
cin>>s;
n=s.length();
for(j=0;j<n/2;j++)
{
s1[j]=s[j];
}
if(n%2==0)
{
for(j=n/2;j<n;j++)
{
s2[j]=s[j];
}
}
else if(n%2!=0)
{
for(j=n/2+1;j<n;j++)
{
s2[k]=s[j];
k++;
}
}
for(a=0;a<n/2;a++)
{
for(b=0;b<(n/2)-1;b++)
{
if(s1[j]>s1[j+1])
{
ch=s1[j];
s1[j]=s1[j+1];
s1[j+1]=ch;
}
}
}
for(a=0;a<n/2;a++)
{
for(b=0;b<(n/2)-1;b++)
{
if(s2[j]>s2[j+1])
{
ch=s1[j];
s2[j]=s2[j+1];
s2[j+1]=ch;
}
}
}
if((s1.compare(s2))==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
also prefer ++x instead of x++ for most use cases
Ольга
Hello. I ask one question.
int sum(int *row, int size) {
int s = 0;
for (size--; size >= 0; size--) s += row[size];
return s;
}
Maybe someone knows how make this function for columns not for row. I I hope someone can help. Thanks in advance
paper
Ольга
Ni
Guys, I am recently reading csapp, and it has the following saying:
"For example, with single precision floating point the expression (3.14+1e10)-1e10 evaluates to 0.0—the
value 3.14 is lost due to rounding. On the other hand, the expression 3.14+(1e10-1e10) evaluates to 3.14."
So I tested it:
float a = (3.14 + 1e10) - 1e10;
float b = 3.14 + (1e10 - 1e10);
printf("%f\n", a); // 3.139999
printf("%f\n", b); // 3.140000
Why the behavior of my code is different from the book?
Raphael
Hii can l have C programming books
Anonymous
Hadaward 'Solly'
Anonymous
Ni
Ni
Anonymous
Hi all,
Any one is working via turing.com
Anonymous
I need support, regarding this one.
Can you update here.
Margo
I have a problem
Without a complicated function, only with loops, can I validate user input of two numbers not being anything then integers?
So like
Cin >>num1>>num2
And after validation
Anonymous