Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
189 views

Assingment 1-Sme 1013 Exercise 1 Answer

This document contains code snippets that demonstrate various C programming concepts like data types, constants, arithmetic operations, and mathematical functions. It tests the validity of different constant types and expressions, and prints the results of calculations and function calls to the screen.

Uploaded by

AbenCintata
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
189 views

Assingment 1-Sme 1013 Exercise 1 Answer

This document contains code snippets that demonstrate various C programming concepts like data types, constants, arithmetic operations, and mathematical functions. It tests the validity of different constant types and expressions, and prints the results of calculations and function calls to the screen.

Uploaded by

AbenCintata
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ASSINGMENT 1- SME 1013 Exercise 1 /*My Program start here*/ #include<stdio.

h> main () { int b, e, i, j, k, l; float a, c, d, f, g, h; Display value on the screen a=0.5; printf("a = %f \n\n", a); This floating-point constant is valid.. Display value on the screen This decimal integer constant is invalid because illegal character (,) Answer

b=27,822; printf("b = %d \n\n", b);

c=9.5e12; printf("c = %f \n\n", c);

Display value on the screen This floating-point constant is valid.

d=9.3e-12; printf("d = %f \n\n", d);

Display value on the screen This floating-point constant is valid.

e = 1234567; printf("e = %d \n\n", e);

Display value on the screen This decimal integer constant is valid.

Display value on the screen f = .9; printf("f = %f \n\n", f); This floating-point constant is valid.

g = 0.8E+0.8; printf("g = %f \n\n", g);

This floating-point constant is invalid because exponents must be an integer quantity (it cant contain a decimal point).

h = 0.8E 8; printf("h = %f \n\n", h);

This floating-point constant are invalid because illegal character (blank space) in the exponent.

i = 0515; printf("i = %d \n\n", i);

Display value on the screen This octal integer constant is valid.

j = 018CDF; printf("j = %d \n\n", j);

This numerical values are invalid because illegal character (8), ( 8 is not in the octal integer constant). This numerical values are invalid because illegal character (G), ( G is not in the Hexadecimal integer constant).

k = 0XDEFG; printf("k = %d \n\n", k);

l = 0x87e3ha; printf("l = %d \n\n", l);

This numerical values are invalid because illegal character (h), (h is not in the Hexadecimal integer constant).

Exercise 2 /*My Program start here*/ include<stdio.h> main() { Answer

int i=8, j=5; float x=0.005, y=-0.01; char d='d'; x + y; printf("x + y = %f \n\n", x + y);

i % j + 2; printf("i % j + 2 = %d \n\n", i % j + 2);

j+i*x; printf("j+i*x = %f \n\n", j+i*x);

(j+i) * x; printf("(j+i) * x = %f \n\n", (j+i) * x);

j/i; printf("j/i = %d\n\n",j/i);

-(i+j); printf("-(i+j) = %d \n\n", -(i+j));

2*((i/5)+(4*(j-3))%(i+j-2)); printf("2*((i/5)+(4*(j-3))%(i+j-2)) = %d \n\n",2*((i/5)+(4*(j-3))%(i+j-2)));

j + (int)(x); printf("j + (int)(x) = %d\n\n",j + (int)(x)); d; printf("d =%c\n\n", d);

++d; printf("++d =%c\n\n", ++d); }

Exercise 3 /*My Program start here*/ #include<stdio.h> #include<math.h> main() { int i=8, j=5; float x=0.005, y=-0.01; abs(i-2*j); printf("abs(i-2*j) = %d\n\n\n", abs(i-2*j)); Answer

fabs(x+y); printf("fabs(x+y) = %f\n\n\n", fabs(x+y)); ceil(x+y); printf("ceil(x+y)= %f\n\n\n", ceil(x+y)); floor(x); printf("floor(x) = %f\n\n\n",floor(x)); sqrt(x*x + y*y); printf("sqrt(x*x + y*y) = %f\n\n\n", sqrt(x*x + y*y)); log(x); printf("log(x) = %f\n\n\n", log(x)); pow(x-y,3.0); printf("pow(x-y,3.0) = %f\n\n\n", pow(xy,3.0)); sin(x-y); printf("sin(x-y) = %f\n\n\n", sin(x-y)); }

You might also like