C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++ tutorials and pdf
above code is incorrect. removind + and i from the scanf the code will work fine. New and simple version for the above problem is #include int main() { int a,b,c,d,e,f; printf("\nEnter the first complex number "); scanf("%d %d",&a,&b); printf("\nFirst number is "); printf("%d + %di",a,b); printf("\nEnter the first complex number "); scanf("%d %d",&c,&d); printf("\nSecond number is "); printf("%d + %di",c,d); e = a*c - b*d; f = a*d + b*c; printf("\nAfter multiplication "); printf("%d+%di",e,f); return 0; }
ya...it's very simple n easy 2 understand.....i have a doubt....for d above 1 ...while reading 1ly u gave dat format...in d similar way i also tried..but i got a garbage value...if v give like dat compiler will take garbage values na...how do i overcome dis problem...
#include typedef struct COMPLEX{ int a; int b; }Complex; Complex multiply(Complex,Complex); int main() { int a1,b1,a2,b2; Complex x,y,z; printf("Enter real part of first complex number : "); scanf("%d",&a1); printf("Enter img part of first complex number : "); scanf("%d",&b1); printf("\nEnter real part of second complex number : "); scanf("%d",&a2); printf("\nEnter img part of second complex number : "); scanf("%d",&b2); x.a = a1; x.b = b1; y.a = a2; y.b = b2; z = multiply(x,y); printf("\nAfter multiplication real part of new complex number: %d",z.a); printf("\nAfter multiplication img part of new complex number: %d",z.b); return 0; } Complex multiply(Complex x,Complex y) { Complex z; z.a = x.a*y.a - x.b*y.b; z.b = x.a*y.b + x.b*y.a; return z; }
4 comments:
above code is incorrect. removind + and i from the scanf the code will work fine.
New and simple version for the above problem is
#include
int main()
{
int a,b,c,d,e,f;
printf("\nEnter the first complex number ");
scanf("%d %d",&a,&b);
printf("\nFirst number is ");
printf("%d + %di",a,b);
printf("\nEnter the first complex number ");
scanf("%d %d",&c,&d);
printf("\nSecond number is ");
printf("%d + %di",c,d);
e = a*c - b*d;
f = a*d + b*c;
printf("\nAfter multiplication ");
printf("%d+%di",e,f);
return 0;
}
ya...it's very simple n easy 2 understand.....i have a doubt....for d above 1 ...while reading 1ly u gave dat format...in d similar way i also tried..but i got a garbage value...if v give like dat compiler will take garbage values na...how do i overcome dis problem...
Hi parnaeeth
enter the number in that format. For example
5+10i
#include
typedef struct COMPLEX{
int a;
int b;
}Complex;
Complex multiply(Complex,Complex);
int main()
{
int a1,b1,a2,b2;
Complex x,y,z;
printf("Enter real part of first complex number : ");
scanf("%d",&a1);
printf("Enter img part of first complex number : ");
scanf("%d",&b1);
printf("\nEnter real part of second complex number : ");
scanf("%d",&a2);
printf("\nEnter img part of second complex number : ");
scanf("%d",&b2);
x.a = a1; x.b = b1;
y.a = a2; y.b = b2;
z = multiply(x,y);
printf("\nAfter multiplication real part of new complex number: %d",z.a);
printf("\nAfter multiplication img part of new complex number: %d",z.b);
return 0;
}
Complex multiply(Complex x,Complex y)
{
Complex z;
z.a = x.a*y.a - x.b*y.b;
z.b = x.a*y.b + x.b*y.a;
return z;
}
Post a Comment