Showing posts with label tutorials FAS. Show all posts
Showing posts with label tutorials FAS. Show all posts

Sunday, January 20, 2013

Practicle test help

1)Create function to take two integer arguments and compare them and if no1 > no2 then swam them.

                 void swapGreater(int number1, int number2);

2)Create function to take an array as a input argument and shift larger walue in to the last array element.

                 void arraySort(int *array);


                 first array look - 12, 300 ,4 ,56 , 67, 3
                 after swap  - 12 , 4,56,67,3,300


3) Create function to read values to array from key board.

                void takeInputs(int *array);

4) Create function to dsplay values from array .

                void displayValues(int *array);

5)
 Create the main mehod and do the following.

                      create array with 6 elements;
                      take values from keybord using takeInputs function.
                     do 5 times arraySort function call to the array.
                     display the array using displayValues function

** this question is 100% not the same , but the program u have to write for this problem is same as the practical test.

ANSWER..............

#include<stdio.h>

void swapGreater(int *no1, int *no2);

void arraySort(int array[]);

void takeInput(int *array);

void display(int *array);


main(){


int array[6],i;

takeInput(array);

printf("before sort !! \n");

display(array);

for(i=0;i<5;i++){

arraySort(array);

}

printf("after sort !! \n");

display(array);


}


void swapGreater(int *no1, int *no2){

int temp;

if(*no1 > *no2){

temp = *no1;

*no1 = *no2;

*no2 = temp;

}



}


void arraySort(int array[]){

int i;

for(i=0;i<5;i++){

swapGreater(&array[i],&array[i+1]);

}



}


void takeInput(int *array){

int i;

printf("enter 6 values \n");

for(i=0;i<6;i++){

scanf("%d",&array[i]);

}


}


void display(int *array){

int i;

for(i=0;i<6;i++){

                printf("%d \n",array[i]);

        }


}



Thursday, November 29, 2012

Exercises (arrays, pointers, functions).

Exercises (arrays, pointers, functions).


1. Write a program to update the value of the double variable flt_num from 123.45 to 543.21 by
using a double pointer.

2. Given a character variable ch and ch = ‘A’, write a program to update the value of ch to
character 'a' by using a pointer.

3. Given an integer array initialized as (int niceArray[]={23,4,4,56,45,5,6,1,34,787};), write a
program to increase each array element by 1000 using a nother pointer.

4. Write a function to calculate a factorial value. Then use that function to calculate 6C2 (possible
combinations in selecting 2 out of 6) and display the value.
(Hint: int factorial(int f1); combinations=factorial(6)/(factorial(2)*factorial(4)); )

5. Write seperate functions,
1. to read an integer value from the keyboard, (int readNumber(); )
2. to display two integer values, (void display(int a,int b); )
3. to swap two integer values, (void swap(int *c,int *d); )
Write a program to read two integer values to two variables, display them
before their values are swaped between them then swap those values and
finally display the two variables. (Hint: Use above functions)

Thursday, November 22, 2012

Loop Assignment Answers

Loop Assignment Answers


1) Write a program to display numbers from 1 to 250.

2) Write a program to calculate the sum of all the numbers less than a given number n.
ex: output
Enter number : 3
6
Enter number : 5
15




3) Write a program to display “hello world” for every time we enter the character 'y' and stop the
program when we enter the character 'n'. For any other character program should not stop or
display anything.

4) Write a program to calculate the factorial value for a given number N.

5) Write a program to calculate number of possible combinations that we can have when we
selecting r number of elements from n number of different elements. This can be calculated by
calculating the value n!/(r!*(n-r)!).

Thursday, November 15, 2012

Assignment Answers

Assignment Answers

1) Write a program to check the given number is positive or negative.


2) Write a program to Add two numbers if the first one is greater than the second number if not
display an error message.


3) Write a program to display the grade (A, B, C or D) according to the given mark.
hint: A(between 100 and 75)/ B(between 74 and 65)/ C(between 64 and 55)/ D(between 54 and
0)

4) Write a program to read a two characters and display them if both are not equal.
5) Write a program to input a temperature reading in either Celsius (c) or Fahrenheit (f)scale and
convert it to the other scale. The temperature reading consists of a decimal integer followed by
letter “F” or “f” if the temperature is in Fahrenheit scale or letter “C” or “c” if it is in Celsius
scale. You may use a similar format for the output of the program.








Monday, July 30, 2012

Assignment 01-cmis1223


Assignment 01-cmis1223


1). School Teacher of a Primary School want a software program to calculate the average marks for
Maths, English, Science and Art for a Student.
1. Use the first three steps of the Development Cycle(Define the
problem:input/output/processing, Outline the solution:main Computation/input
variables/intermediate results, Develop an algorithm) to come up with an algorithm.


Inputs : Maths mark , Englsh mark , Science mark
Process :  Calculate average marks
Output  :   Average mark

  calAverage
1.sum <-  (math_mark + English_mark+Science_marrk)
2.average <- sum / 3


2. Write a C program for the Problem.

#include<stdio.h>

main(){

float M_marks , E_marks , Sc_marks;
float Average;

printf("Please enter Maths marks \n");
scanf("%f \n"&M_marks);
printf("Please enter English marks \n");
scanf("%f \n"&E_marks);
printf("Please enter English marks \n");
scanf("%f \n"&Sc_marks);

Average = (M_marks+E_marks+Sc_marks)/3;

printf("Average marks for three subject is %f \n", Average);
}



2). This program is developed to calculate the Age of a living person.

#include <stdio.h>
main() {
int day,month,year;
int bday,bmonth,byear;
printf("\n********Quiz01!********\n");
printf("\nEnter the Todays Date:\f");
scanf("%d/%d/%d",&day,&month,&year);
printf("\nEnter your Birth Day:\f");
scanf("%d/%d/%d",&bday,&bmonth,&byear);
printf("Your Age for Today: %d\n",year-byear);
}


1. Explain the Execution of this program.

#include <stdio.h>

main() {

int day,month,year;     // create memory locations in the main memory

int bday,bmonth,byear; // create memory locations in the main memory

printf("\n********Quiz01!********\n"); // print the text on screen  ********Quiz01!********

printf("\nEnter the Todays Date:\f"); // prin the text Enter the Todays Date

scanf("%d/%d/%d",&day,&month,&year); // blinking curser , values are assign to the relavant memory locations

printf("\nEnter your Birth Day:\f"); // print the text Enter your Birth Day

scanf("%d/%d/%d",&bday,&bmonth,&byear);  //blinking curser , values are assign to the relavant memory locations


printf("Your Age for Today: %d\n",year-byear); // your age for tody year-byear

}




2. Does this program correctly calculates the age of a person? If not explain why?

NO , there is unused variables in this program , day , bday , month , bmonth . Tocalulate the age precisely  have to use this variables as well .

right code to calulate the age precisely -
printf("Your Age for Today: %d  yaers %d  months %d days \n",year-byear , month - bmonth , day-bday);


Tuesday, June 26, 2012

CMIS Practicle Tute 2 Answers

1) A Program is required to display the square and cube of a number input by a user .