Monday, October 6, 2014

Last asm...




int main(int argc, char *argv[]) {
int x,i,v,mkm1,mkm2;
int b=1000000;
int z=123456;
char r[10];
printf ("-------------------------------He thong ATM kich hoat.--------------------------");
printf ("\n-Xin chao :Nguyen Van A");
for(i=0;i<100;i++){
printf("\n-Xin moi nhap mat khau cua ban:");scanf("%d",&x);
printf("                         ---Dang kiem tra thong tin---");
if(x==z){
printf("\n                 ---Chuc mung ban da dang nhap thanh cong---");
i=100;                  //Menu hinh chinh
for (i=1;i<100;i++){
printf("\n--------------------------Chao mung ban den voi he thong ATM .------------------");
printf("\n                       ||1.Kiem tra so du trong tai khoan.  ||");
printf("\n                       ||2.Rut tien.                        ||");
printf("\n                       ||3.Chuyen khoan.                    ||");
printf("\n                       ||4.Doi mat khau.                    ||");
printf("\n                       ||0.Ket thuc giao dich.              ||");
int a;
printf("\n#Chon:");scanf("%d",&a);
                     //ops 1:Kiem tra tk
if(a==1){
printf("-Ten chu tai khoan:Nguyen Van A");
printf("\n-So du trong tai khoan:%d(k VND)",b);
}
                     //ops 2:Rut tien
else if(a==2){
printf("-So du trong tai khoan cua ban la:%d (k VND)",b);
printf("\n-Nhap so tien ban muon rut:");scanf("%d",&v);
printf(".....Dang rut tien.....");
printf("\n.........Xong..........");
printf("\n-So du cua ban:%d(k VND)",b-v);
b=b-v;                  
}
                     //ops 3:Chuyen khoan
else if(a==3){
    printf("\nSo tien trong tai khoan cua ban:%d (k VND)",b);
    printf("\nNhap so tai khoan muon chuyen:");scanf("%d",&x);
    printf("\nSo tien muon chuyen: "); scanf("%d", &v);
    printf("\n......Dang chuyen.........");
    printf("\n.........Xong.............");
    printf("\nSo du trong tai khoan cua ban:%d (kVND)",b-v);
    b=b-v;
    }
                         //ops 4:Doi mat khau ca nhan
else if (a==4){
    printf("Ban da lua chon doi mat khau...");
    printf("Yeu cau nhap mat khau cu:");scanf("%d",&x);
    if(x==z){
    printf("Nhap mat khau moi:");scanf("%d",&mkm1);
    printf("Nhap lai mat khau moi:");scanf("%d",&mkm2);
    if (mkm2==mkm1){
    printf("Doi mat khau thanh cong.");
    z=mkm1;
        }
    else{
    printf("Mat khau khong chinh xac");
    }
    }
           }
                     //ops 0:Thoat chuong trinh
    else if(a==0){
    printf("--------------------------Chuc ban mot ngay tot lanh.--------------------------");
    i=100;
      }
    }
}
else{
printf("Mat khau khong chinh xac.");
}
}
return 0;
}

Thursday, October 2, 2014

Exercise array 02

1. Write a program which prints the letters in a char array in reverse order. For example, if the array contains {'c', 's', 'c', '2', '6', '1'}the output (to the terminal) should be "162csc"

2. Write a  program : declare a char array and the size of the array (of type char). This function counts the number of digit letters in the char array.


3. Write a program that counts the number of words in a string


4. Write a program that accept two string, after checking if string1 equals string2 then print 'string 1 equals string2', else print string1 less than or greater than string 2.


5. Write a function that scans a character array for the character - and replaces it with _


Sunday, September 28, 2014

Test 2...

#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int isPrime(int N);
int main(int argc, char *argv[]) {
    int N;
  printf("Enter a number:");scanf("%d", &N);
    int isPrime(int N){
    int i;
    for(i=2; i<N; i++){
if(N%i != 0){
    return 1;
    }
    else{
    return 0;
    }
    }
}
if(isPrime(N)){
printf("Number is prime");
  }
  else{
  printf("Number is not prime");
  }
  return 0;
}


Exercise_array 1(day 5)

1. Write a program that asks the user to type 10 integers of an array. The program must compute and write how many integers are greater than or equal to 10.


2. Write a program that asks the user to type 10 integers of an array. The program must output the largest element in the array, and the index at which that element was found.


3. Input values are accepted from the user into the array. Displays highest of the entered values. Prints average of values entered.


4. Write a program that accepts the following numbers in an array and reverses the array


6. Write a program that asks the user to type 10 integers of an array and an integer V. The program must search if V is in the array of 10 integers. The program writes "V is in the array" or "V is not in the array".

7. Write a program that asks the user to type 10 integers of an array and an integer value V. The program must search if the value V exists in the array and must remove the first occurrence of V, shifting each following element left and adding a zero at the end of the array. The program must then write the final array


8. Write a program that asks the user to type 10 integers of an array and an integer value V and an index value i between 0 and 9. The program must put the value V at the place i in the array, shifting each element right and dropping off the last element. The program must then write the final array


Exercise 11: dowhile-loop (day4)

1. Declare a variable which has the age of the person. Print the user’s name as many times as his age


2. The program displays even numbers from 1 to 30.


3. The program displays numbers from 10 to 0 in the reverse order


4. The program will accept integers and display them until zero (0) is entered


5.  Find the factorial of a number.


Tuesday, September 23, 2014

Assignment

int main(int argc, char *argv[]) {
 float x,y[12];
 int i,j;
 for (i = 0; i < 12; i++){
  printf("Month %d : ", i+1);
  scanf("%f", &y[i]);
 }
 for (i = 11; i > 0; i--){
  for (j = 11; j >= 12 - i; j--){
   if (y[j] > y[j-1]){
    x = y[j-1];
    y[j-1] = y[j];
    y[j] = x;
   }
  }
 }
 printf("Ssort descending:\n");
 for (i = 0; i < 12; i++){
  printf("%.2f ", y[i]);
 }
 printf("\nTop 3 months with highest sales amount\n");
 for (i = 0; i < 3; i++){
  printf("%.2f \n", y[i]);
 }
 return 0;
}

Exercise:For loop (day 4)


1. Declare a variable which has the age of the person. Print the user’s name as many times as his age:


2. The program displays even numbers from 1 to 30.


3. The program displays numbers from 10 to 0 in the reverse order.



4. The program will accept integers and display them until zero (0) is entered



6.  Write a program to print the series 100, 95 , 90, 85,………., 5.



Thursday, September 18, 2014

Exercise: while (day 4)


1. Declare a variable which has the age of the person. Print the user’s name as many times as his age:

2. The program displays even numbers from 1 to 30:



3. The program displays numbers from 10 to 0 in the reverse order:


4. The program will accept integers and display them until zero (0) is entered:



5.  Find the factorial of a number.




6.  Write a program to print the series 100, 95 , 90, 85,………., 5.




7.   Accept two numbers num1 and num2. Find the sum of all odd numbers between the two  numbers entered .




Tuesday, September 16, 2014

Exercice 8-More conditial (day 3)

1.  Declare two variables x and y. Assign values to these variables. Number x should be printed only if it is less than 2000 or greater than 3000, and number y should be printed only if it is between 100 and 500.


2.  Write a program to show your computer’s capabilities. The user types in a letter of the alphabet and your program should display the corresponding language or package available. Some sample input ans output is given below :
                           Input                                  Output
                           A or a                                Ada
                           B or b                                 Basic
                           C or c                                 COBOL
                           D or d                                dBASE III
                           f or F                                  Fortran
                           p or P                                 Pascal
                           v or V                                Visual C++
Using the ‘switch’ statement to choose and display the appropriate message. Use the default label to display a message if the input does not match any of the above letters. 
       

3.  Accept values in three variables and print the highest value.

Sunday, September 14, 2014

Exercise 7: More if...(day 3)

1.  Write a program that accepts two numbers a and b and checks whether or not a is divisible by b.


2.  Write a program to accept 2 numbers and tell whether the product of the two numbers is equal to or greater than 1000.



3. Write a program to accept 2 numbers. Calculate the difference between the two values. If the difference is equal to any of the values entered, then display the following message : Difference is equal to value <number of value entered> If the difference is not equal to any of the values entered, display the following message: Difference is not equal to any of the values entered



Exercise obout if...

Challenge 2:


Challenge 3:
Done!

Exercise with ball...

Đề bài đơn giản là quả bóng sẽ bị rơi xuống,chúng ta cần cho nó k bị rơi xuống quá màn hình nữa.
Ở bài này,chúng ta sử dụng câu lệnh "if",đặt điều kiện cho sự di chuyển của quả bóng,làm nó k rơi xuống nữa.
Dùng "if" với điều kiện khi ball vượt quá tọa độ 370,nhận đc kết quả tốc độ đổi từ 2 xuống -2(tức là ball đi ngược lên trên)

Tương tự,đặt thêm 1 điều kiện để ball rớt xuống khi qua toạn độ y=30,tránh để ball bay quá màn hình.

Friday, September 12, 2014

Exercise get()/puts()...


1.   Write a program to accept and add three numbers.



2.  For the following values, write a program to evaluate the expression:


z = a*b+(c/d)-e*f ;


  a=10
  b=7
  c=15.75
  d=4
  e=2
  f=5.6      


3. Write a program to evaluate the area and perimeter of the rectangle:


4.  Write a program to evaluate the volume of a cylinder.






Using printf() and scanf()...


1. Use the printf( )  statement and do the following:

a)    Print out the value of the integer variable sum
b)  Print out the text string "Welcome", followed by a new line.
c)  Print out the character variable letter
d)  Print out the float variable discount
e) Print out the float variable dump using two decimal places


2. Use the scanf( )  statement and do the following:

a) To read a decimal value from the keyboard, into the integer variable sum

b) To read a float variable into the variable discount_rate

c)Print the wth Values of the characters ‘A’ and ‘b’.