Anonymous
this is the problem: alex has written a programm that prints numbers from 1 to 5000 in deifferent lines but unfortunately his \t has a problem and the programm has producted a huge number "12345678910111213141516..." now he want know the k'th number of this huge number. for example input 10 and output 1
#include<iostream> using namespace std; int main() { int k; double x; cin>>k; if(k<10) { cout<<k; } if(k>9&&k<190) { x=(k-9)/2.0; if(x-int(x)!=0) { x=int (x)+1; } x=x+9; if(k%2==0) cout<<int (x)/10; else cout<<int (x)%10; } if(k>189&&k<2890) { x=(k-189)/3.0; if(x-int (x)!=0) { x=int (x)+1; } x+=99; if(k%3==0) { cout<<int (x)%10; } else if(k%3==1) { cout<<int (x)/100; } else if(k%3==2) { cout<<(int (x)/10)%10; } } if(k>2889) { x=(k-2889)/4.0; if(x-int (x)!=0) { x=int (x)+1; } x+=999; if(k%4==2) { cout<<int (x)/1000; } else if(k%4==3) { cout<<(int(x)/100)%10; } else if(k%4==0) { cout<<(int(x)/10)%10; } else if(k%4==1) { cout<<int(x)%10; } } return 0; }
Anonymous
i wrote that
Shiva
/notes
Anonymous
I don't know what is fstream and broken text
broken text is a text file where the number is saved, fstream is the same as cin/cout just for files instead of console. you can use python to create broken.txt just type: with open("broken.txt", "w") as fstr: for n in range(1, 5001): fstr.write(str(n))
Anonymous
i'm a new learner😬
Anonymous
why don't you use using namespace std;
you can use it of course, if you write bigger programs sometime it can cause problems to use "using namespace std"
Pavel
why don't you use using namespace std;
https://www.geeksforgeeks.org/using-namespace-std-considered-bad-practice/amp/
Anonymous
i'm a new learner😬
yeah c++ is very hard to learn for new programmers, if you need more help just ask. Do you know any other programming languages?
Anonymous
And i am also a learner
Anonymous
int n,a=2,i; cin>>n; for(i=1;i<n;i+2) { a+=4; } cout<<a;
Anonymous
does anyone know why this loop doesn't print an output for n=3?
SS
int n,a=2,i; cin>>n; for(i=1;i<n;i+2) { a+=4; } cout<<a;
For next iteration the i becomes 3 ans 3 <3 fails
SS
Use i<=n It will print for 3
SS
i know but it must print 6
It is not printing 6 ?
Anonymous
in my codeblocks and also in online compiler
Anonymous
i+=2
aaaah thank you😂🤦🏽‍♂️
Anonymous
trouble mistake
Engineer
Anyone have user experience of using the omp.h include file? #include <omp.h>
Ww
hello every one any one can tell me what the code for this exercise Exercise 1 : Write a C++ program that reads a character. If the character input is a space, print a message specifying it. If the character input is a digit, print a message specifying it. its home work for my brother and he so sick i’ve try to understand but i can’t so please help me
Ww
hello ... any one ?
klimi
use getch and if
isn't getch non standard?
klimi
i would say it is better to use something like fgetc or rather getchar()
Anonymous
isn't getch non standard?
i think. because we can't use #conio.h in our exercises
Anonymous
but he still can use cin>> for input
klimi
i think. because we can't use #conio.h in our exercises
well yeah because conio.h is DOS thing isn't it?... if he is using c++ he could use std::cin also
Anonymous
what do you study?
klimi
what do you study?
well it's in my bio
Anonymous
well it's in my bio
computer sicence?
klimi
computer sicence?
#ot yeah, but let's move into the offtopic group if you want to discuss that
Anonymous
does anyone work with SDL2?
Hello, I am using cmake, and I want to build a library created by linking the same source file compiled with several different macro, how to achieve it?
Anonymous
char ch = a
Anonymous
int(ch) will return its ascii number
Anonymous
letters a-z are ascii number 65-122, this is easy to check in c or c++ program
Anonymous
int(ch) will return its ascii number
you don't need to know ascii code you can put the letter between ' '
Anonymous
you don't need to know ascii code you can put the letter between ' '
but how do you check if input is any letter from a-z with yourmethod?
Suka
but how do you check if input is any letter from a-z with yourmethod?
if(x>='a' && x<='z'){ }?
Anonymous
if(x>='a' && x<='z'){ }?
i dont think this works but maybe im wrong about it
Leovan
I am forced to use Windows by my work and don't understand some things. On Linux all libs situated in /usr/include directory, on Windows we can store libraries where we want and give paths to compilator or cmake. But another programmer can store required lib in another place, so he cant compile my code by my cmake (or another instructions). How to make independent this moment?
Leovan
hm, interesting, ty
Kate
Hello! Might you help me please? I want to include libraries with the extension *.dll to the project. I found that it is possible to include libraries with the extension *.lib to the project like this: #pragma comment(lib,"MyDll.lib") How could I do something like this for the *.dll-files?
Anonymous
I'm using Visual Studio
Im not too familiar with VS, I think I remember there is a way to add it from GUI but maybe someone else can help you more specifically
Kate
Am new here
klimi
Am new here
okay, great, but you don't have to broadcast that to everyone, thanks
klimi
Okay sorry for that
thank you. It would be very unfortunate if all 16k members started sending such messages, I hope you understand
Dennastus
/get cppbooks
Dennastus
/get cppebooks
Dennastus
/get cppbookguide
Anonymous
do anyone have chegg account ?
Amonov
/get cppbookguide
Nana
#include <iostream> #include <vector> #include <ctime> #include <cstdlib> using namespace std; void intro(); int main() { intro(); vector<int>vect; vector<int>nonRepeat; int size; int num; int min = 1, max = 10; int val; cout<<"\t\tEnter the size of the vector: "; cin>>size; cout<<endl; unsigned seed = time(0); srand(seed); for(int count = 0; count < size; count++) { num = (rand() % (max - min +1)) + min; vect.push_back(num); } cout<<"\t\tHere are the numbers\n"; cout<<endl; for( int count = 0; count < size; count++) { cout<<"\t\tNum #"<<count + 1<<" = "<<vect[count]<<endl; } return 0; } void intro() { cout<<"\t\tThis is a c++ program\n"; cout<<"\t\t----------------------------\n"; cout<<endl; }
Nana
no but some are repeated
SMS
i see
SMS
I think the most easy way is to go through vect, check if the new number is already exists, and regenerate it if it does
Shao
Or you can try to store directly to the array without random and then get it through the array subscript