#26 C Struct | C Programming for Beginners
Вставка
- Опубліковано 5 вер 2024
- #26 C Struct | C Programming for Beginners
In this video, we will learn about struct in C programming. More specifically, we will learn to store related data together under a single name using struct. And we will also learn the use of an alias. Watch out for this video to have a clear understanding of struct in C programming.
Sign Up to get 50% off with this link: app.programiz....
This video is a part of our C Programming video series: • #1: Getting Started wi...
~
Resources:
C Online Compiler: www.programiz....
Github File: github.com/pro...
C (title) Tutorial (text-based tutorial): www.programiz....
Timestamps:
0:16 - C Struct
07:35 - typedef in Struct
08:50 - Sum of Complex Numbers
12:38 - Programming Task
13:17 - Quiz
~
Revise your learning using our C App
Download here for Android: bit.ly/3upaInx
Download here for iOS: apple.co/3EZLtNq
Find Programiz elsewhere:
Programiz pro: programiz.pro/
Website: www.programiz.com
Discord: / discord
Facebook: / programiz
Instagram: / _programiz
LinkedIn: / programiz
Twitter: / programiz
#programiz #struct #cprogramming #learnprogramming #typedef #alias
🔥Finding it Damn Hard to Understand C Programming?
Learn to code-the right way-with interactive lessons, quizzes & challenges. Build a strong programming base; it's IMPORTANT!
Try Programiz PRO for Free: bit.ly/master-c-programming
#include
typedef struct complex
{int real;
int imaginary;}
complex;
int main() {
complex c1 = {.real=12,.imaginary=9};
complex c2 = {.real=3,.imaginary=2};
complex c3 = {.real=7,.imaginary=8};
complex difference;
difference.real= c1.real-c2.real-c3.real;
difference.imaginary=c1.imaginary-c2.imaginary-c3.imaginary;
printf("the sum is %d%di",difference.real,difference.imaginary);
return 0;
}
I like when she says "let me sow you" instead of "show", it's just so cute
#include
#include
#include
#include
typedef struct Complex {
int real;
int imagine;
} complex;
int main()
{
complex c1 = {.real = 10, .imagine = 20};
complex c2 = {.real = 5, .imagine = 15};
complex c3 = {.real = 25, .imagine = 30};
complex minus;
minus.real = c1.real - c2.real - c3.real;
minus.imagine = c1.imagine - c2.imagine - c3.imagine;
printf("Total is: %d and %di", minus.real, minus.imagine);
return 0;
}
OUTPUT:
Total is: -20 and -25i
/*
Create a program to find the differences
between three complex numbers.
* Perform the subtraction between
complex numbers by subtracting the
real part of one complex number from
other complex numbers and same for
the imaginary part too.
*/
#include
//Differences of Complex Numbers
typedef struct Complex{
double real;
double imagine;
}complex;
int main(){
complex c1 = {.real = 45.34, .imagine = 15};
complex c2 = {.real = 21.34, .imagine = 30};
complex c3 = {.real = 13.34, .imagine = 10.5};
complex sub;
sub.real = c1.real - c2.real - c3.real;
sub.imagine = c1.imagine - c2.imagine - c3.imagine;
printf("Result is %.2lf - %.2lfi", sub.real, sub.imagine);
return 0;
}
Very basic tutorial but high-quality for beginner,expecting more videos for C language
you have helped many all around the world a lot! thank you so much!
What's her fb id & insta id?
I'm also learning c programming language. Your Program learn trick very amazing mam ❤️ Thank you so much love u mam ❤️❤️
What's her fb id & insta id?
i have one question what is the main use for struct as more variable can be take to do the work? Is it related to memory of operation check?
Amaizing Thank youuuuuuuuu I havew lab of programming tomorrow and is about this thank uuuuuuuuuuuuuuuuuuuuuuuuuuu
opt c , first test
At the last in quiz answer will be....(c) firstTest 💥💥💥💥
Thanks
Thank you so much. Tnx for sharing your knowledge generously.
Hi Panoha, i'm from Peru (latinoamerica), your videos are amazing thank for it, that i help me a lots.
Thanks a lot for the video, but I have one question. 9:30 Why did we add "Complex" after the "typedef struct"? We did not use "Complex" anywhere in the last version of the code. And without using it, the program still works.
This is because she used "typedef" at the beginning of the definition. By doing so, she created an alias of "complex" which represents "struct Complex". So anywhere in the code that you see "complex" that is substituting for "struct Complex".
Hello again! i am back at it finally and here is my solution for the Programming task:
#include
typedef struct complex{
double real;
double imaginary;
}complex;
int main(){
complex num1 = {.real = 121.05, .imaginary = 130.1};
complex num2 = {.real = 20.05, .imaginary = 30.2};
complex num3 = {.real = 2, .imaginary = 30.3};
complex sum;
sum.real = num1.real - num2.real - num3.real;
sum.imaginary = num1.imaginary - num2.imaginary - num3.imaginary;
printf("Result of %.2lf + %.2lfi", sum.real, sum.imaginary);
return 0;
}
and for the quiz i'm thinking C. firstTest because if i'm not mistaken that's how you create a quick nickname thing
(just fyi i looked it up now its not a nickname, its like you're initializing or declaring a variable of that struct type immediately after defining the structure itself, which i think is neat to know )
very helpfull!
Mam I need more structure videos such as pointer to structure,self referencial structure and singly linked list please post these videos for me
Your video are crisp and easy to understand
Big fan of your sites and videos 😜
Mam explain this program in the next vedio write a c program to read a sentence and count the number of pf words in the sentence
Thanks for this explanation!
Maadam miruu thopp🔥💥
What's her fb id & insta id?
#include
typedef struct Complex {
double real;
double imagine;
} complex;
int main() {
complex c1 = {.real = 3496.54, .imagine = 67.07};
complex c2 = {.real = 672.41, .imagine = 23.14};
complex c3 = {.real = 27.06, .imagine = 42.15};
complex subtraction;
subtraction.real = c1.real - c2.real - c3.real;
subtraction.imagine = c1.imagine - c2.imagine - c3.imagine;
printf("Result is %.2lf + %.2lfi", subtraction.real, subtraction.imagine);
return 0;
}
Great job. Thank you for this.
I am having problems with C progamming for engineers I am worried I will not do well on my finaly exam as I need 20%out of 40% to pass. That's what I am here. Seeking help. Please do you have a detailed video as to why you use the typedef and other methods of initializing struts. I don't mined I will pay for it
Thank you!
option d
Thanks ma'am
#include
typedef struct complex{
double real;
double imaginary;
} complex;
int main(){
complex c1={.real=23.26 , .imaginary=15.56};
complex c2={.real=13.26 , .imaginary=5.56};
complex subtract;
subtract.real=c1.real - c2.real;
subtract.imaginary=c1.imaginary - c2.imaginary;
printf("difference between c1 and c2 is %.2lf + %.2lfi",subtract.real,subtract.imaginary);
return 0;
}
comment leaved
#include
typedef struct complex{
double real;
double imagine;
}complex;
int main()
{
complex x={.real=73.7, .imagine=143.8};
complex y={.real=45.3, .imagine=112.4};
complex substract={.real=x.real-y.real, .imagine=x.imagine-y.imagine};
printf("RESULT: %.1lf + %.1lfi",substract.real,substract.imagine);
return 0;
}
Quiz: What is the name of the variable of the following struct?
struct Test {
double testScore;
int testCount;
} firstTest;
a. testScore
b. struct
c. firstTest
d. Test
firstTest is the structure variable of
type struct Test.
first test
a. testScore
First test
A
I try take string value in struct but not work...how to solve.?
ty
You are the best❤
Answer is option c mam
Mam, When will the searching and sorting video come out in this series?
First test
C. firstTest
Option : test
answer : C
firstTest
Your Laptop Spec. ?🤩🤩
❤
first test
#include
typedef struct complex{
double Real;
double Imaginary;
} complex;
int main()
{
complex a1 = {.Real = 43.2, .Imaginary =23.32};
complex a2 = {.Real = 34.44, .Imaginary = 32.33};
complex sum;
sum.Real = a1.Real - a2.Real;
sum.Imaginary = a1.Imaginary - a2.Imaginary;
printf("the Real of complex is %.1lf
the Imaginary of complex is %.2lf
", sum.Real, sum.Imaginary);
return 0;
}
My Answer is c
#include
typedef struct complex{
double real;
double imaginary;
}comp;
int main() {
comp c1 = { .real=41.5, .imaginary=20};
comp c2 = {.real=10.6, .imaginary=5};
comp c3 = {.real=15.2, .imaginary=2.3};
comp diff;
diff.real=c1.real-c2.real-c3.real;
diff.imaginary=c1.imaginary-c2.imaginary-c3.imaginary;
printf("The Difference is %.2lf + %.2lfi",diff.real,diff.imaginary);
return 0;
}
c
c.firstTest
nice bro
typedef struct complexnum {
int real, imag;
} complexnum;
int main() {
int resultreal, resultimag;
complexnum c1 = {.real = 8, .imag = 5 };
complexnum c2 = {.real = 6, .imag = 2 };
complexnum c3 = {.real = 3, .imag = 7 };
resultreal = c1.real - c2.real - c3.real;
resultimag = c1.imag - c2.imag - c3.imag;
printf("the result is: Z=%d%di
", resultreal, resultimag);
return 0;
# include
typedef struct Difference {
double real;
double imaginary;
double answer;
}difference;
int main() {
difference c1 = {.real = 34.14, .imaginary = 112.34};
difference c2 = {.real = 21.12, .imaginary = 80.21};
difference minus;
minus.real = c1.real - c2.real;
minus.imaginary = c1.imaginary - c2.imaginary;
minus.answer = minus.imaginary - minus.real;
printf("Result is %.2lf - %.2lf = %.2lf",minus.imaginary,minus.real,minus.answer);
return 0;
}
Option C : firstTest
---------------------------------------------------------------------------------
#include
typedef struct complex
{
double real;
double imagine;
}complex;
int main()
{
complex c1 = {.real = 23.56, .imagine = 47.2};
complex c2 = {.real = 11.28, .imagine = 25.7};
complex c3 = {.real = 9.38, .imagine = 14.4};
complex diff;
diff.real = c1.real - c2.real - c3.real;
diff.imagine = c1.imagine - c2.imagine - c3.imagine;
printf("Difference is %.2lf - %.2lfi", diff.real, diff.imagine);
return 0;
}
#include
typedef struct Complex {
double real;
double imagine;
} complex;
int main() {
complex c1 = {.real = 144.8, .imagine = 188.4};
complex c2 = {.real = 84.6, .imagine = 68.55};
complex c3 = {.real = 48.9, .imagine = 24.6};
complex difference;
difference.real = c1.real - c2.real - c3.real;
difference.imagine = c1.imagine - c2.imagine - c3.imagine;
printf("Result is %.2lf + %.2lfi", difference.real, difference.imagine);
return 0;
}
output: Result is 11.30 + 95.25i
#include
typedef struct Numbers{
double real;
double imagine;
}numbers;
int main(){
numbers n1 = {.real = 600, .imagine = 300};
numbers n2 = {.real = 200, .imagine = 200};
numbers n3 = {.real = 100, .imagine = 100};
numbers diff;
diff.real = n1.real - n2.real - n3.real;
diff.imagine = n1.imagine - n2.imagine - n3.imagine;
printf("The difference is: %.2lf + %.2lfi", diff.real, diff.imagine);
return 0;
#include
typedef struct Complex {
double real;
double imaginary;
} complex ;
int main() {
complex num1 = {.real = 123.32, .imaginary = 69};
complex num2 = {.real = 312.35, .imaginary = 63};
complex num3 = {.real = 323.32, .imaginary = 609};
complex difference;
difference.real = num1.real - num2.real - num3.real ;
difference.imaginary = num1.imaginary - num2.imaginary - num3.imaginary ;
printf("The difference of the three complex numbers are %.2lf - %.2lfi ", difference.real, difference.imaginary);
return 0;
}
Task:
#include
struct Complex {
double real;
double imagine;
};
int main() {
struct Complex complex1 = {.real = 35.56, .imagine = 45};
struct Complex complex2 = {.real = 45.76, .imagine = 75.67};
struct Complex complex3 = {.real = 105.86, .imagine = 146.98};
struct Complex sub;
sub.real = complex3.real - complex2.real - complex1.real;
sub.imagine = complex3.imagine - complex2.imagine - complex1.imagine;
printf("Result: %.2lf + %.2lfi ", sub.real, sub.imagine);
OUTPUT: Result: 24.54 + 26.31i
Quiz: C is the correct option
#include
typedef struct Complex {
double real;
double imagine;
}complex;
int main(){
complex c1 = {.real = 11.12 , .imagine = 13.14};
complex c2 = {.real = 14.15 , .imagine = 15.16};
complex c3 = {.real = 16.17 , .imagine = 17.18};
complex sub;
sub.real = (c1.real) - (c2.real) - (c3.real) ;
sub.imagine = (c1.imagine) - (c2.imagine) - (c3.imagine) ;
printf("%.2lf + %.2lfi ", sub.real , sub.imagine);
return 0;
}
#include
typedef struct Complex{
double real;
double imaginary;
} complex;
int main(){
double imaginary;
complex c1 = {.real =5, imaginary = 2};
complex c2 = {.real =2, imaginary = 4};
complex c3 = {.real =7, imaginary = 1};
complex sub1,sub2,sub3;
sub1.real = c1.real - c2.real;
sub2.real = c2.real - c3.real;
sub3.real = c3.real - c1.real;
sub1.imaginary = c1.imaginary -c2.imaginary;
sub2.imaginary = c2.imaginary -c3.imaginary;
sub3.imaginary = c3.imaginary -c1.imaginary;
printf("c1- c2 is %.2lf + (%.2lfi)
", sub1.real ,sub1.imaginary);
printf("c2- c3 is %.2lf + (%.2lfi)
", sub2.real ,sub2.imaginary);
printf("c3- c1 is %.2lf + (%.2lfi)", sub3.real ,sub3.imaginary);
return 0;
}
firstTest
First test
Thanks
#include
typedef struct Complex {
double real;
double imagine;
} complex;
int main() {
complex c1 = {.real = 221.87, .imagine = 330};
complex c2 = {.real = 13.34, .imagine = 112.23};
complex c3 = {.real = 27.13, .imagine = 22.16};
complex sub;
sub.real = c1.real - c2.real - c3.real;
sub.imagine = c1.imagine - c2.imagine - c3.imagine;
printf("Result is %.2lf + %.2lfi", sub.real, sub.imagine);
return 0;
}