Phoenix
Oh is it necessary?
Phoenix
Will i have to use pointers or reference variables for doing this?
\Device\NUL
Oh is it necessary?
use pointer to change data value outside function
Pavel
Which one has best performance ? for (int i = 0;;) for (int i = 0;;) or int i; for (i = 0;;) for (i = 0;;)
In C/C++ it doesnt matter, at least for basic types like int. I mean both should be the same in performance
Prabhat
Where should I look it I want to study pointers in detail?
Ammar
Which one has best performance ? for (int i = 0;;) for (int i = 0;;) or int i; for (i = 0;;) for (i = 0;;)
It doesn't really matter, it's just about the variable scope. Your int i here is very likely just a register. Paying attention to something like this does really matter for non trivial object where we need to know exactly when the destructor gets called. But for your example, it doesn't matter.
Talula
Which one has best performance ? for (int i = 0;;) for (int i = 0;;) or int i; for (i = 0;;) for (i = 0;;)
Actually in Assembly/Machine code it really doesn't matter both would be same, because compiler will assign it the location... unless you're writing in Java or C# (I think).
Cybersecurity Engineer
Hi I’m new here I want learn C programming language need your help suggestions and your guide🙏🏽
Çağlar
As for me, we should make a list or program for the new programmers. list may includes programming subject and excercises so when juniours are attend the page they can easily take the program it just only suggestion : )
Çağlar
There are websites (a lot of them?) with programming challenges, tutorials and learning materials
actually thats right. however there are huge amount of web pages and documents also books contains in internet but which ones are appropriate to start. thanks in advance
Deepak
Best playlist for learning python For beginners.?
Dr
Best playlist for learning python For beginners.?
Try programming with mosh (YouTube)
Anonymous
Now days which are the best course to learn easy or beginning of the programming language please suggest
M
Hey folks
Anton
Hi I’m new here I want learn C programming language need your help suggestions and your guide🙏🏽
I’m not sure if I’m allowed to send links in the chat. So try to google for “best c books stackoverflow”. First link would be good for starters I suppose.
Markiyan
Hi guys, my task is to create (let's say db) for toys using array of structures, where you can enter some data, display, filter by child age, sort it by name or by price. I have 2 issues: 1) This string always appears after executing command user@user-Latitude-7480:~/labs$ ./a.out List of commands: (E)nter Sort by (N)ame Sort by (P)rice (F)ilter by minimal age (D)isplay all (Q)uit Choose command: D Name Price Maker Child age 0.00 0 0.00 0 0.00 0 0.00 0 0.00 0 0.00 0 **Choose command: Such command doesn't exist** Choose command:
Markiyan
2) I don't know how to create sort of whole array
Markiyan
Here is source code
Markiyan
#include <stdio.h> struct toy { char name[10]; float price; char maker[10]; int min_age; } record[5]; void enter(int i) { printf("Enter name: "); scanf("%s", record[i].name); printf("Enter price: "); scanf("%f", &(record[i].price)); printf("Enter maker: "); scanf("%s", record[i].maker); printf("Enter minimal age: "); scanf("%d", &(record[i].min_age)); } void display() { int i; printf("\nName\tPrice\tMaker\tChild age\n"); for(i=0;i<=5;++i) { if(record[i].price = 0.0) { break; } printf("%s\t%.2f\t%s\t%d\n", record[i].name, record[i].price, record[i].maker, record[i].min_age); } } void filter(){ int i, age; printf("Enter child age: "); scanf("%d", &age); printf("\nName\tPrice\tMaker\tChild age\n"); for(i=0;i<=5;++i) { if (record[i].min_age == age) { printf("%s\t%.2f\t%s\t%d\n", record[i].name, record[i].price, record[i].maker, record[i].min_age); } } } void main() { int i = 0; char command; printf("List of commands:\n(E)nter\nSort by (N)ame\nSort by (P)rice\n(F)ilter by minimal age\n(D)isplay all\n(Q)uit\n"); while(1) { printf("\nChoose command: "); scanf("%c", &command); switch(command) { case 'E': enter(i); ++i; break; case 'N': printf("sort(name);"); break; case 'P': printf("sort(price);"); break; case 'F': filter(); break; case 'D': display(); break; case 'Q': return; default: printf("Such command doesn't exist\n"); break; } } }
Markiyan
Thanks in advance
Anonymous
Assalamualaikum
Anonymous
I want to learn c language from starting any one teach me here plzzzz plzzzzzzzzzzz plzzzzzzzzzzz
Cybersecurity Engineer
/get
Markiyan
Choose command: Such command doesn't exist
\Device\NUL
Choose command: Such command doesn't exist
record[i].price is undefined tho
M
No github links allowed? That is kind of weird though wouldn't you think
Markiyan
record[i].price is undefined tho
I defined it here struct toy { char name[10]; float price; char maker[10]; int min_age; } record[5];
Markiyan
You mean like this? ``` struct toy { char name[10]; float price = 0.0; char maker[10]; int min_age; } record[5]; ```
Anonymous
Hello guys can anyone help me please
Anonymous
I have a code, it's giving me a segmentation fault But i cannot find the error
Anonymous
So can someone verify it for me
\Device\NUL
Just dontasktoask
Anonymous
What's that?
Anonymous
Just dontasktoask
What do you mean? Help please
\Device\NUL
Anonymous
#include<stdio.h> void printArray(int *A, int n) { for(int i = 0;i < n; i++) { printf("%d ", A[i]); } printf("\n"); } void merge(int A[],int mid,int low,int high) { int i,j,k,B[100]; i=low; j=mid+1; k=low; while(i<= mid && j <= high) { if(A[i]<A[j]) { B[k]=A[i]; i++; k++; } else { B[k]=A[j]; j++; k++; } } while(i<=mid) { B[k]=A[i]; k++; i++; } while(j<=high) { B[k]=A[j]; k++; i++; } for(i=low;i<=high;i++) { A[i]=B[i]; } } void mergeSort(int A[],int low,int high){ int mid; if(low < high) { mid= (low + high)/2; mergeSort(A,low,mid); mergeSort(A, mid+1, high); merge(A, mid, low, high); } } int main() { int A[]={2,7,4,4,11,21}; int n=6; printArray(A, n); mergeSort(A, 0, 5); printArray(A, n); return 0; }
Anonymous
Yes
Anonymous
(Low < high)
Anonymous
this is not related about C/C++ but can i someone explain me or show me what and how to do the system integration design?
Melbgm
Hi guys. I am new to C programming. If the amount is 200 or more, how can I write the job of finding the discounted amount by making a 25% discount on the second product?
Melbgm
oid main() { float price1; float price2; float totalprice; float discount_amount; float discounted_price; printf("\n\n Enter Price of first Item : "); scanf("%f", &price1); printf("\n\n Enter Price of second Item : "); scanf("%f", &price2); totalprice = price1 + price2; if (totalprice > 200) discount_amount = (25 * price2) / 100; discounted_price = (totalprice - discount_amount); printf("\n\nDiscount amount : %f \n\n", discount_amount); printf("Discounted price : %f \n\n", discounted_price); // getch(); }
Melbgm
what is wrong with my code ?
Melbgm
normally it says void main, incompletely copied
\Device\NUL
normally it says void main, incompletely copied
main func must be returned int data type
Melbgm
oh 😱 You're right
Melbgm
#include <stdio.h> void main() { float price1; float price2; float totalprice; float discount_amount; float discounted_price; printf("\n\n Enter Price of first Item : "); scanf("%f", &price1); printf("\n\n Enter Price of second Item : "); scanf("%f", &price2); totalprice = price1 + price2; if (totalprice > 200) { discount_amount = (25 * price2) / 100; } discounted_price = (totalprice - discount_amount); printf("\n\nDiscount amount : %f \n\n", discount_amount); printf("Discounted price : %f \n\n", discounted_price); // getch(); }
Melbgm
still not working do you have any other solution
\Device\NUL
Also, how hard to use int main rather than void main
Melbgm
Changing it
Melbgm
#include <bits/stdc++.h> int main() { float price1; float price2; float totalprice; float discount_amount; float discounted_price; } printf("\n\n Enter Price of first Item : "); scanf("%f", &price1); printf("\n\n Enter Price of second Item : "); scanf("%f", &price2); totalprice = price1 + price2; if (totalprice > 200) { discount_amount = (25 * price2) / 100; } if else (totalprice <=200) { discount_amount = (0 * price2) / 100; } discounted_price = (totalprice - discount_amount); printf("\n\nDiscount amount : %f \n\n", discount_amount); printf("Discounted price : %f \n\n", discounted_price); // getch(); }
Melbgm
Any idea ?
shriman_deepak
#include <bits/stdc++.h> int main() { float price1; float price2; float totalprice; float discount_amount; float discounted_price; } printf("\n\n Enter Price of first Item : "); scanf("%f", &price1); printf("\n\n Enter Price of second Item : "); scanf("%f", &price2); totalprice = price1 + price2; if (totalprice > 200) { discount_amount = (25 * price2) / 100; } if else (totalprice <=200) { discount_amount = (0 * price2) / 100; } discounted_price = (totalprice - discount_amount); printf("\n\nDiscount amount : %f \n\n", discount_amount); printf("Discounted price : %f \n\n", discounted_price); // getch(); }
#include <bits/stdc++.h> int main() { float price1; float price2; float totalprice; float discount_amount; float discounted_price; printf("\n\n Enter Price of first Item : "); scanf("%f", &price1); printf("\n\n Enter Price of second Item : "); scanf("%f", &price2); totalprice = price1 + price2; if (totalprice > 200) { discount_amount = (25 * price2) / 100; } else { discount_amount = (0 * price2) / 100; } discounted_price = (totalprice - discount_amount); printf("\n\nDiscount amount : %f \n\n", discount_amount); printf("Discounted price : %f \n\n", discounted_price); return 0; // getch(); }
shriman_deepak
https://pastebin.com/b1yvVWBy
shriman_deepak
https://pastebin.com/b1yvVWBy
please anyone help me how to skip new line character in fgetc for this code ?
Nana
Hello
Nana
I need your help guys
Nana
7. Name Arranger Write a program that asks for the user’s first, middle, and last names. The names should be stored in three different character arrays. The program should then store, in a fourth array, the name arranged in the following manner: the last name followed by a comma and a space, followed by the first name and a space, followed by the middle name. For example, if the user entered “ Carol Lynn Smith”, it should store “ Smith, Carol Lynn” in the fourth array. Display the contents of the fourth array on the screen.
Nana
#include <iostream> #include <cstring> using namespace std; void name_arrangement(char [], char[], char[]); void intro(); int main() { int length = 50; char first_name[length]; char last_name[length]; char middle_name[length]; intro() cout<<"Enter your first name: "; cin.getline(first_name, length); cout<<endl; cout<<"Enter your second name: "; cin.getline(last_name, length); cout<<endl; cout<<"Enter your middle name: "; cin.getline(middle_name, length); cout<<endl; name_arrangement(first_name, last_name, middle_name); return 0; } void intro() { cout<<"This is a name arrangement program in C++\n"; cout<<"-------------------------------------------\n"; cout<<endl; } void name_arrangement(char first_name[], char last_name[], char middle_name[]) { while(*first_name != '\0') { if(strcmp(first_name, last_name) < 0) { if(strcmp(last_name, middle_name) < 0) cout<<last_name<<" "<<first_name<<" "<<middle_name<<endl; } else if(strcmp(first_name, last_name) > 0) { if(strcmp(last_name, middle_name) > 0) cout<<last_name<<" "<<first_name<<" "<<middle_name<<endl; } first_name++; } }
Nana
The else if part does not work. I don't know how to store the sorted names in a fourth variable. Pls help me
klimi
?
Nana
No. sorting should be done using strcmp() in c++
Anonymous
how to see defination in vscode