Ashish
Or send me the pdf from where i can learn it
Lava
Just see a course on udacity or coursera , edx etc
Ashish
Sry for that
Gulshan
Why did you took cs if you want to cheat in exam ?
Gulshan
You may have selected another stream of your liking... Why to waste parents hard earned money
Xudoyberdi
su
Xudoyberdi
Rifat
Write a program using while loop that ask the user about how many number he/she wants to enter. Your task is to take input those many number and calculate their sum.
»
#include <stdio.h>
int main ()
{
int n,i,sum = 0;
scanf("%d",&n);
i=1;
while (i<=n)
{
sum +=i*10;
++i;
}
printf("%d\n",sum);
return 0;
}
Rifat
can anyone let me know what's wrong with that? I am not getting expected answer
su
Rifat
Apk
Rifat
Apk
you don't need to store actually
Apk
in the while loop, you can take input and add it to the sum, without any need to store the input
Apk
But if you really want to store, use an array
ברני
#include <stdio.h>
int main() {
int n, i, sum = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
i = 1;
while (i <= n)
{
sum += i;
++i;
}
printf("Sum = %d", sum);
return 0;
}
Rifat
ברני
And don't send pics, the admins will warn you
Lava
Idk c ,but in c++ logically I would put a variable that takes the number the user enters and the value of that variable is being added to sum on each loop run . The loop would run till the 'n' number of numbers user wants to enter
Lava
I see that you only took in / scanned the n value but not the numbers the user wants the sum of .
Roshan
Anonymous
how do i split stereo to mono and recombine
ברני
Hey, I have a task on C that I didn't understand well Question 2 - to run
Write a function that takes a set of two-dimensional NXN squares and its size (number of rows / number of columns) and updates the main diagonal members in the value of the maximum member in the row.
You must write and use an auxiliary function which receives a one-dimensional array and its size and returns the maximum limb in it. **************************************** why do I need single array function? for the calculation?
Alex
could you suggest c++ code analyzer for linux?
Gulshan
Gulshan
Btw which distro?
Alex
ubuntu. should I add cppcheck to CMakefile?
Alex
what is the usual approach?
Alex
I don`t like gui. Ok probably, I will add it as Emacs shortcut
Gulshan
Gulshan
Then man cppcheck
Gulshan
Alex
should I use build system or integrate it to IDE
Andrey
why many people write code like this:
while((*s++ = *t++) != '\0')
;
isnt better to write this version?
while((*s++ = *t++) != '\0');
ברני
ברני
That the semicolon is a line down?
Xudoyberdi
Andrey
ברני
yes
Yes you right, it is better
ברני
You know what is better then that?
for loops 😏
olli
Anonymous
Hi, how do I list all files of an entire drive in a text file?
I have been able to list files of only one directory at a time with WinAPIs.
Can anyone suggest me something?
Anonymous
Alex
what details do you need?
Георгий
Anonymous
What functions should I use I have got FindFirstFile, dirent struct and C++17 recursive_directory_iterator?
Anonymous
Age???
Dima
wtf
Ali
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <float.h>
int main() {
char machine_a[4];
char machine_b[4];
char machine_c[4];
char extra_var;
printf("enter the name for first machine.\n");
fgets(machine_a , 4, stdin);
extra_var = getchar();
printf("enter the name for second machine\n");
fgets(machine_b , 4, stdin);
extra_var = getchar();
printf("enter the name for third machine.\n");
fgets(machine_c , 4, stdin);
extra_var = getchar();
float a = 0.0, b = 0.0, c = 0.0;
float x;
float total_production;
float max_production = -1;
float min_production=flt_max;
char max_machine[4];
char min_machine[4];
printf("enter the 2 productions of machine %s:\n", machine_a);
scanf("%f", &x);
a = a + x;
scanf("%f", &x);
a = a + x;
if(a > max_production) {
max_production = a;
strcpy(max_machine,machine_a);
}
if(a < min_production) {
min_production = a;
strcpy(min_machine , machine_a);
}
printf("enter the 2 productions of machine %s:\n", machine_b);
scanf("%f", &x);
b = b + x;
scanf("%f", &x);
b = b + x;
if(b > max_production) {
max_production = b;
strcpy(max_machine , machine_b);
}
if(b < min_production) {
min_production = b;
strcpy(min_machine , machine_b);
}
printf("enter the 2 productions of machine %s:\n", machine_c);
scanf("%f", &x);
c = c + x;
scanf("%f", &x);
c = c + x;
if(c > max_production) {
max_production = c;
strcpy(max_machine , machine_c);
}
if(c < min_production) {
min_production = c;
strcpy(min_machine , machine_c);
}
total_production = a + b + c;
float avg_production = total_production / 3;
printf("total production: %0.1f\n", total_production);
printf("average production: %0.1f\n", avg_production);
printf("machine with maximum production: %s\n", max_machine);
printf("machine with minimum production: %s\n", min_machine);
return 0;
}
Ali
Any one can debug
Dima
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <float.h>
int main() {
char machine_a[4];
char machine_b[4];
char machine_c[4];
char extra_var;
printf("enter the name for first machine.\n");
fgets(machine_a , 4, stdin);
extra_var = getchar();
printf("enter the name for second machine\n");
fgets(machine_b , 4, stdin);
extra_var = getchar();
printf("enter the name for third machine.\n");
fgets(machine_c , 4, stdin);
extra_var = getchar();
float a = 0.0, b = 0.0, c = 0.0;
float x;
float total_production;
float max_production = -1;
float min_production=flt_max;
char max_machine[4];
char min_machine[4];
printf("enter the 2 productions of machine %s:\n", machine_a);
scanf("%f", &x);
a = a + x;
scanf("%f", &x);
a = a + x;
if(a > max_production) {
max_production = a;
strcpy(max_machine,machine_a);
}
if(a < min_production) {
min_production = a;
strcpy(min_machine , machine_a);
}
printf("enter the 2 productions of machine %s:\n", machine_b);
scanf("%f", &x);
b = b + x;
scanf("%f", &x);
b = b + x;
if(b > max_production) {
max_production = b;
strcpy(max_machine , machine_b);
}
if(b < min_production) {
min_production = b;
strcpy(min_machine , machine_b);
}
printf("enter the 2 productions of machine %s:\n", machine_c);
scanf("%f", &x);
c = c + x;
scanf("%f", &x);
c = c + x;
if(c > max_production) {
max_production = c;
strcpy(max_machine , machine_c);
}
if(c < min_production) {
min_production = c;
strcpy(min_machine , machine_c);
}
total_production = a + b + c;
float avg_production = total_production / 3;
printf("total production: %0.1f\n", total_production);
printf("average production: %0.1f\n", avg_production);
printf("machine with maximum production: %s\n", max_machine);
printf("machine with minimum production: %s\n", min_machine);
return 0;
}
/warn read the rules
Dima
BRUH
Anonymous
Anonymous
Help me with c
Xudoyberdi
Артём
How does std::initializer_list's ctor work under the hood? In other words, how can I work with braced-init-list without using std::initializer_list?
Артём
I'm sorry but all my google results refer to use of std::initializer_list, but I need not to deal with STL.
Lava
Can we use void functions as int functions by just getting them to return a garbage value ? Will it effect the output ?
Talula
Lava
So if I do
int display( int num )
{
cout<< num ;
return 0;
}
It won't compile ?
Roshan
Lava
Not in habit of writing void 😅
Hadaward 'Solly'
well
Hadaward 'Solly'
there's always a first time
Talula
Lava
Roshan
Lava
Ok , I will try to get used to void then . Thank you all .