20940 cmp102 intr.to sci.& engineering comp final …tax = 100 + 0.2 x (gross pay – 1000)...

12
26.05.2010 20940 CMP102 Intr.to Sci.& Engineering Comp Final Examination Number:…………….. Name/Surname:…………….. Signature:………………. 1- Write a program to read in 10 numbers and compute the average, maximum and minimum values. 2) Write C expressions for the following mathematical expression. a) )] ( [ 1 z y x x E b) 3 cos 2 3 sin x x x x x x c) 2 ) 1 ( 1 x x k d) 1 1 ) 1 ( 4 2 2 x x x y 3) What will be the output of the following program fragments ? a) for (j=2,i=3;i<=8;i+=2) { j+=i; } printf("%d %d\n",i,j); b) c) int sum,k,x; sum=0.0; x=1; for(k=1;k<=4;k++) {x=x+4; if(x>10) break; sum+=x;} printf("x=%d,sum=%d,\n",x,sum); d) int ROW =5; int COL =2; int a[ROW][COL]={10,20,30,40,50,60,70,80,90,100}; int b[ROW][COL]={5,10,15,20,25,30,35,40,45,50}; int c[ROW][COL]; a) Screen Layout b) Screen Layout d) Screen Layout c) Screen Layout int x; void fonk(void) {x=200; } void main () { x=100; printf("x=%d\n",x); fonk(); printf("x=%d\n",x); }

Upload: others

Post on 10-Jul-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 20940 CMP102 Intr.to Sci.& Engineering Comp Final …tax = 100 + 0.2 x (gross pay – 1000) 1.2.3. compute net pay: net pay = gross pay –tax 1.3. print gross pay, tax and net pay

26.05.2010 20940 CMP102 Intr.to Sci.& Engineering Comp

Final Examination Number:…………….. Name/Surname:…………….. Signature:………………. 1- Write a program to read in 10 numbers and compute the average, maximum and minimum values. 2) Write C expressions for the following mathematical expression.

a) )]([1

zyxx E

b) 3

cos23

sinx

xxxxx

c) 2)1

(1x

xk

d) 1

1)1(4

22

xx

xy

3) What will be the output of the following program fragments ? a) for (j=2,i=3;i<=8;i+=2) { j+=i; } printf("%d %d\n",i,j); b) c) int sum,k,x; sum=0.0; x=1; for(k=1;k<=4;k++) {x=x+4; if(x>10) break; sum+=x;} printf("x=%d,sum=%d,\n",x,sum); d) int ROW =5;

int COL =2; int a[ROW][COL]={10,20,30,40,50,60,70,80,90,100}; int b[ROW][COL]={5,10,15,20,25,30,35,40,45,50}; int c[ROW][COL];

a) Screen Layout

b) Screen Layout

d) Screen Layout

c) Screen Layout

int x; void fonk(void) {x=200; } void main () { x=100; printf("x=%d\n",x); fonk(); printf("x=%d\n",x); }

Page 2: 20940 CMP102 Intr.to Sci.& Engineering Comp Final …tax = 100 + 0.2 x (gross pay – 1000) 1.2.3. compute net pay: net pay = gross pay –tax 1.3. print gross pay, tax and net pay

i=2; j=1; c[i][j]=a[i][j]+b[i][j]; printf("[%d][%d]=%d\n",i,j,c[i][j]); 29.05.2009 23049 CMP102 Intr.to Sci.& Engineering Comp

Final Examination Number:…………….. Name/Surname:…………….. Signature:………………. 1) The tax rate is 10% of the first $1000 and 20% of all additional income. Design an algorithm for printing the gross pay, the tax with held, and net pay of an employee, given the numbers of hours worked and hourly wage rate. The desired algorithm is as fallows: 1.1. Read hours worked and wage rate 1.2. Do computations:

1.2.1. Compute gross pay: gross pay = hours worked x wage rate 1.2.2. Compute tax: if gross pay is less than 10000 then tax = 0.1 x gross pay otherwise tax = 100 + 0.2 x (gross pay – 1000) 1.2.3. compute net pay: net pay = gross pay –tax

1.3. print gross pay, tax and net pay 1.4. Stop. 2) Write C expressions for the following mathematical expression.

a) 21 434

xxxx

b) 21sin

xxk

c) 21 43

)43(21

xx

xx

d)

xxxx

23sin

3) What will be the output of the following program fragments ? a) int i, j; double d; i= 7; j=9; d=1.3; i=i + j; d=d + j; i= d * j; printf("%5d, %6.3f\n”,i, d); b)

a) Screen Layout

for(a = 1; a <= 5; a = a + 1) { for( b = 1; b <= 5; b = b + 1) printf("%d", b); printf("\n"); }

b) Screen Layout

Page 3: 20940 CMP102 Intr.to Sci.& Engineering Comp Final …tax = 100 + 0.2 x (gross pay – 1000) 1.2.3. compute net pay: net pay = gross pay –tax 1.3. print gross pay, tax and net pay

c) int a; float b=6, c =18.6; a=c/b; printf("%d \n",a); d) int x[5] [2]={8, 20, 4,30,6,15, 7,43,2, 55}; printf (“x(3,1) = %5d\n”, x[2][1]) 29.05.2009 23049 CMP102 Intr.to Sci.& Engineering Comp

Final Examination Number:…………….. Name/Surname:…………….. Signature:………………. 1)The commission on a salesman’s total sales is as follows: Sales < $200 No commision. $200 <= Sales < $2000 Commission = 12% of sales. Sales >= $2000 Commission = $200 + 18% of sales above $2000. Write a program that reads sales and prints out the salesman’s commission. 2) Write C expressions for the following mathematical expression.

a) 21 434

xxxx

b) 21sin

xxk

c) 21 43

)43(21

xx

xx

d)

xxxx

23sin

3) What will be the output of the following program fragments ? a) int i=2, j=1, k=3; k%= i * j; printf("%d\n”,k); b) x=0; switch(x) { case 1: printf("One"); case 0: printf("Zero"); case 2: printf("Hello World");} c) int a; float b=6, c =18.6; a=c/b; printf("%d \n",a);

a) Screen Layout

b) Screen Layout

c) Screen Layout

d) Screen Layout

c) Screen Layout

Page 4: 20940 CMP102 Intr.to Sci.& Engineering Comp Final …tax = 100 + 0.2 x (gross pay – 1000) 1.2.3. compute net pay: net pay = gross pay –tax 1.3. print gross pay, tax and net pay

d) int x[5] [2]={8, 20, 4,30,6,15, 7,43,2, 55}; printf (“x(3,1) = %5d\n”, x[2][1]) WIN32 CONSOLE APPLICATION bahattin.cpp : Defines the entry point for the console application. #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { float a,b,c; printf("iki sayının toplamı \n \n"); printf("birinci sayıyı girin\n"); scanf("%f",&a);

printf("ikinci sayıyı girin\n"); scanf("%f",&b); c=a+b; printf("sonuç\n"); printf("%f",c); printf("Bir Tuşa Basınız"); getchar(); getchar(); return 0; } stdafx.cpp : source file that includes just the standard includes // bahattin.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information #include "stdafx.h" // TODO: reference any additional headers you need in STDAFX.H // and not in this file stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently

d) Screen Layout

Page 5: 20940 CMP102 Intr.to Sci.& Engineering Comp Final …tax = 100 + 0.2 x (gross pay – 1000) 1.2.3. compute net pay: net pay = gross pay –tax 1.3. print gross pay, tax and net pay

// #pragma once #include "targetver.h" #include <stdio.h> #include <tchar.h> // TODO: reference additional headers your program requires here denklem.cpp : Defines the entry point for the console application. #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { float a,b,c; double delta,x1,x2; printf("denklemin katsayılarını girin\n"); printf("a katsayısını girin\n"); scanf("%f",&a); printf("b katsayısını girin\n"); scanf("%f",&b); printf("c katsayısını girin\n"); scanf("%f",&c);

delta=b*b-4*a*c; if(delta<0) {printf("kök yok\n"); getchar(); getchar(); return 0; } else { x1=(-b+sqrt(delta))/(2*a); x2=(-b-sqrt(delta))/(2*a); printf("x1=%f\n",x1); printf("x2=%f\n",x2); } getchar(); getchar(); return 0; } stdafx.cpp : source file that includes just the standard includes // denklem.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information #include "stdafx.h"

Page 6: 20940 CMP102 Intr.to Sci.& Engineering Comp Final …tax = 100 + 0.2 x (gross pay – 1000) 1.2.3. compute net pay: net pay = gross pay –tax 1.3. print gross pay, tax and net pay

// TODO: reference any additional headers you need in STDAFX.H // and not in this file stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently #pragma once #ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later. #define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows. #endif #include <stdio.h> #include <tchar.h> #include <math.h> #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { double sum,x; int k; sum=0.0; for(k=1;k<=20;k++) { scanf("%lf",&x); if(x>10.0) continue; sum+=x; } printf("sum=%f\n",sum); getchar(); getchar(); return 0; }

#include "stdafx.h" #define PI 3.141593 int _tmain(int argc, _TCHAR* argv[]) { int degrees=0; double radians; printf("Degrees to radians \n"); while (degrees<=360) { radians=degrees*PI/180; printf("%6i %9.6f\n",degrees,radians); degrees+=10; }

Page 7: 20940 CMP102 Intr.to Sci.& Engineering Comp Final …tax = 100 + 0.2 x (gross pay – 1000) 1.2.3. compute net pay: net pay = gross pay –tax 1.3. print gross pay, tax and net pay

getchar(); getchar(); return 0; } #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { int a[10]={100,-200,400,-100,550,900,500,300,450,600}; int toplam,k,amax; toplam=0; amax=a[0]; for(k=0 ;k<10;++k) {toplam+=a[k]; if(amax<a[k]) amax=a[k]; printf("amax=%d\n",amax); } int toplam,k; toplam=0; for(k=0;k<10;++k) {toplam+=a[k]; printf("toplam=%d\n",toplam); } getchar(); getchar(); return 0; }

#include "stdafx.h" #define ROW 5 #define COL 2 int _tmain(int argc, _TCHAR* argv[]) { int a[ROW][COL]={10,20,30,40,50,60,70,80,90,100}; int b[ROW][COL]={5,10,15,20,25,30,35,40,45,50}; int c[ROW][COL]; int i,j; for(i=0;i<ROW;i++) for (j=0;j<COL;j++) { c[i][j]=a[i][j]+b[i][j]; printf("[%d][%d]=%d\n",i,j,c[i][j]);

Page 8: 20940 CMP102 Intr.to Sci.& Engineering Comp Final …tax = 100 + 0.2 x (gross pay – 1000) 1.2.3. compute net pay: net pay = gross pay –tax 1.3. print gross pay, tax and net pay

} getchar(); getchar(); return 0; } using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { int sum,i,j,k,x; Console.WriteLine("Midterm 1 13.04.2010 "); i = 2; j = 1; k = 3; k *= i - j; i /= k + j; x = 1; Console.WriteLine("i={0}",i); Console.WriteLine("k={0}",k); sum = 0; for(k=1;k<=4;k++) {x=x+4; if(x>10) break; sum+=x;} Console.WriteLine(x); Console.WriteLine(sum); int day = 3; int time = 6; if (day <= 5) {

Page 9: 20940 CMP102 Intr.to Sci.& Engineering Comp Final …tax = 100 + 0.2 x (gross pay – 1000) 1.2.3. compute net pay: net pay = gross pay –tax 1.3. print gross pay, tax and net pay

if (time <= 9) Console.WriteLine("Work"); else Console.WriteLine("relax"); } else { if (time <= 8) Console.WriteLine("Sleep"); else Console.WriteLine("Have fun"); } //Prime number (asal sayı for (i = 3; i < 100; i++) { for (k = 2; k < i; k++) for (i = 3; i < 100; i++) { for (k = 2; k < i; k++) { x = i % k; if (x == 0) break; if (x != 0) x = i; } if (x!= 0) Console.WriteLine(x); } Console.ReadLine(); { x = i % k; if (x == 0) break; if (x != 0) x = i; } if (x!= 0) Console.WriteLine(x); }

Page 10: 20940 CMP102 Intr.to Sci.& Engineering Comp Final …tax = 100 + 0.2 x (gross pay – 1000) 1.2.3. compute net pay: net pay = gross pay –tax 1.3. print gross pay, tax and net pay

Console.ReadLine(); } } }

#include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { float temp; /* Temperature reading. */ printf("\n\nGive me the temp read"); scanf("%f",&temp); if ((temp >= 100.0) && ( temp <= 120.0)) printf("Temperature OK, process."); if (temp < 100.0) printf("Temp.too low, inc. energy."); if ((temp > 120.0) && (temp <= 150.0)) printf("Temp.too high, reaseenergy."); if (temp > 150.0) printf("Danger! Shut down systems."); getchar(); getchar(); return 0; } int grade; printf("\n\nNotu girin"); scanf("%d",&grade); if(grade >= 90) printf("A");

Page 11: 20940 CMP102 Intr.to Sci.& Engineering Comp Final …tax = 100 + 0.2 x (gross pay – 1000) 1.2.3. compute net pay: net pay = gross pay –tax 1.3. print gross pay, tax and net pay

else if(grade >= 80) printf("B"); else if(grade >= 70) printf("C"); else if(grade >= 60) printf("D"); else printf("F"); int _tmain(int argc, _TCHAR* argv[]) {int grade,numb; printf("not girin\n"); scanf("%d",&grade); numb=grade/10; switch(numb) { case 9:printf("A\n"); break; case 8:printf("B\n"); break; case 7:printf("C\n"); break; case 6:printf("D\n"); break; default: printf("F\n"); break; } getchar(); getchar(); return 0; } int _tmain(int argc, _TCHAR* argv[]) {

Page 12: 20940 CMP102 Intr.to Sci.& Engineering Comp Final …tax = 100 + 0.2 x (gross pay – 1000) 1.2.3. compute net pay: net pay = gross pay –tax 1.3. print gross pay, tax and net pay

float a,b,c; double x1,x2,delta; printf("a katsayısını girin\n"); scanf("%f",&a); printf("b katsayısını girin\n"); scanf("%f",&b); printf("c katsayısını girin\n"); scanf("%f",&c); delta=b*b-4*a*c; if(delta<0) { printf("kök yok\n"); getchar(); getchar(); return 0; } else { x1=(-b+sqrt(delta))/(2*a); x2=(-b-sqrt(delta))/(2*a); printf("x1=%5.2f\n",x1); printf("x2=%5.2f\n",x2); } getchar(); getchar(); return 0; }