5-5
#include<stdio.h> int main(void) { void pyramid(int n); pyramid(5); return 0; } void pyramid(int n) { int i,j; for(i=1;i<=n;i++){ for(j=1;j<=n-1;j++) printf(" "); for(j=1;j<=i;j++) printf("%d",i); putchar(' '); } }
5-6
#include<stdio.h> float result_real,result_imag; int main(void) { float imag1,imag2,real1,real2; void complex_prod(float real1,float imag1,float real2,float imag2); void complex_add(float real1,float imag1,float real2,float imag2); printf("Enter 1st complex number (real and imaginary):"); scanf("%f%f",&real1,&imag1); printf("Enter 2nd complex number (real and imaginary):"); scanf("%f%f",&real2,&imag2); complex_add(real1,imag1,real2,imag2); printf("addition of complex is%f+%fi ",result_real,result_imag); complex_prod(real1,imag1,real2,imag2); printf("product of complex is%f+%fi ",result_real,result_imag); return 0; } void complex_add(float real1,float imag1,float real2,float imag2) { result_real=real1+real2; result_imag=imag1+imag2; } void complex_prod(float real1,float imag1,float real2,float imag2) { result_real=real1*real2-imag1*imag2; result_imag=real1*imag2+real2*imag1; }
5-7
#include<stdio.h> int x; int f( ); int main(void) { int a=1; x=a; a=f( ); { int b=2; b=a+b; x=x+b; } printf("%d%d",a,x); return 0; } int f( ) { int x=4; return x; }