17 August 2009

Today's C-Programming Lab.

Now i am typing inside the freezing ITMS computer lab.
My tutor is Miss Mona. Actually she is a lecturer too.. She is a very dedicated tutor and lecturer. She just mentioned the Face code that allocated for us in final exam is 5%. She had an allocation of total 20 of marks for total of our final exam total marks.

She gave us these codes and asked us the execute it:

//program that accepts 2 integers
//add them and display the sum value
#include
void main()
{
int first, second, sum;
printf("\please enter the 1st number:");
scanf("%d", &first);
printf("Please enter the 2st number:");
scanf("%d", &second);
sum=first+second;
printf("\nThe sum is %d\n\n", sum);
}



//program that will increase a given value by one
#include
void main(void)
{
int first;
printf("Enter a value:");
scanf("%d", &first);
printf("\nNew Value is : %d\n\n", first+=4);
}



//Program that demonstrate post fix and prefix
#include
void main()
{
int i=5, c=10, x;
x=i++;
printf("a)x=%d\n", x);
x=++x;
printf("b)x= %d\n", x);
x=c++ +i;
printf("c)x= %d\n", x);
}

ans: a=5, b=6, c=c+1 so c)16



//program that determine the larger number
#include
void main(void)
{
int first, second, temp=0;
printf("Please enter the first number=");
scanf("%d", &first);
printf("please enter nthe second number=");
scanf("%d", &second);
if(second>first)
{
temp=second;
second=first;
first=temp;
}
printf("\n%d is bigger than %d\n\n", first, second);
}



//program that performs operation of choice
#include
void main(void)
{
float first, second, result;
char choice;
printf("Please enter the first number=");
scanf("%f", &first);
printf("Please enter the second number=");
scanf("%f", &second);
printf("\nWhat do you want to do with these number?\n\n");
printf("Enter A to add them\n");
printf("Enter D to divide them\n");
scanf("\n%c", &choice);
if(choice='A')
{
result=first+second;
printf("The result is %.2f\n\n", result);
}

scanf("\n%c", &choice);
if(choice='D')
{
result=first/second;
printf("The result is %.2f\n\n", result);
}
}

1 comment:

magnesium said...

C is a general-purpose computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. Although C was designed for implementing system software, it is also widely used for developing portable application software. C is one of the most popular programming languages.