Sie sind auf Seite 1von 11

QUESTION 1.

#include <stdio.h>

main()
{
printf("/*****************************************************************\n");
printf("** Name: Nor Adila binti Ahmad *\n");
printf("** Matric Number: 147703 *\n");
printf("** Purpose: Learning how to write comments in C *\n");
printf("** Date: Written on 21/07/2009 *\n");
printf("** Lecture Group: 2 *\n");
printf("*******************************************************************/\n");
}
QUESTION 2

#include <stdio.h>

main()
{
printf("h\n");
printf("e\n");
printf("l\n");
printf("l\n");
printf("o\n");
printf(" \n");
printf("w\n");
printf("o\n");
printf("r\n");
printf("l\n");
printf("d\n");
}
QUESTION 3

#include <stdio.h>
main()
{
int x=3;
int y=4;
int sum;

sum= x + y;
printf("The sum of %d and %d was %d\n",x,y,sum);
}
QUESTION 4

#include <stdio.h>

main()
{
int number1;
int number2;

printf("Type in a number1 \n");


scanf("%d",&number1);
printf("Type in a number2 \n");
scanf("%d",&number2);
printf("The sum of %d and %d was %d\n",number1,number2,number1 + number2);
}
QUESTION 6

#include <stdio.h>

main()
{
x+1=x
}

ERROR

--------------------Configuration: question6 - Win32 Debug--------------------


Compiling...
question6.c
C:\Users\Adila\Documents\ASSIGNMENT\c++\C++\question6.c(5) : error C2065: 'x' : undeclared identifier
C:\Users\Adila\Documents\ASSIGNMENT\c++\C++\question6.c(6) : error C2106: '=' : left operand must be l-value
C:\Users\Adila\Documents\ASSIGNMENT\c++\C++\question6.c(6) : error C2143: syntax error : missing ';' before '}'
Error executing cl.exe.

question6.obj - 3 error(s), 0 warning(s)


QUESTION 7

#include <stdio.h>

main()
{

int dividend,divisor,quotient,remainder;

printf("Enter a dividend \n");


scanf("%d",&dividend);
printf("Enter a divisor \n");
scanf("%d",&divisor);
quotient=dividend/divisor;
printf("The quotient of %d and %d was %d\n",dividend,divisor,quotient);
remainder=dividend%divisor;
printf("The remainder of %d and %d is %d\n",dividend,divisor,remainder);
}

The normal output.


When negative divisor was inserted.

When divided by 0.
QUESTION 8

#include <stdio.h>

main()
{
int x=9;
printf("%d %d\n",x++,++x);
}
QUESTION 9

#include <stdio.h>
#define PI 3.1416

main()
{
double area, c, r;

r=23.00;
printf("Radius=%5.2f\n",r);

c=2.0 * PI * r;
printf("Circumference=%8.4f\n",c);

area=PI * r * r;
printf("Area=%8.4f\n",area);

}
QUESTION 10

#include <stdio.h>

main()
{
int i=8,j=5;
double x=0.005,y=-0.01;
char c='c',d='d';
int a=(3*i-2*j)%(2*d-c);
int b=2*((i/5)+(4*(j-3))%(i+j-2));
int e=++i;
int f=i++;
int g=5*(i+j)>'c';
int h=2*x+y==0;
int k=(i>0)&&(j<5);
int l=(i>0)||(j<5);

printf("(a) The answer is %d\n",a);


printf("(b) The answer is %d\n",b);
printf("(c) The answer is %d\n",e);
printf("(d) The answer is %d\n",f);
printf("(e) The answer is %d\n",g);
printf("(f) The answer is %d\n",h);
printf("(g) The answer is %d\n",k);
printf("(h) The answer is %d\n",l);
}

Das könnte Ihnen auch gefallen