0% found this document useful (0 votes)
42 views7 pages

Practice For Final LC3

1. The document contains code snippets for 5 programming problems: printing a pattern, calculating the square root of a number, finding the maximum and minimum of 3 numbers, calculating power of two numbers, and changing a character to uppercase. 2. The second problem takes a number as input, calculates its square root if it is greater than or equal to 0, and prints an error message otherwise. 3. The third problem takes 3 numbers as input, finds the maximum and minimum values, and prints them out.

Uploaded by

Phước Phạm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views7 pages

Practice For Final LC3

1. The document contains code snippets for 5 programming problems: printing a pattern, calculating the square root of a number, finding the maximum and minimum of 3 numbers, calculating power of two numbers, and changing a character to uppercase. 2. The second problem takes a number as input, calculates its square root if it is greater than or equal to 0, and prints an error message otherwise. 3. The third problem takes 3 numbers as input, finds the maximum and minimum values, and prints them out.

Uploaded by

Phước Phạm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

PRACTICE FOR FINAL

1. Print
*********

* *

* *

*********

Program:

#include <stdio.h>

main()

int i, j;

for (i = 1; i <= 4; i++)

for (j = 1; j <= 9; j++)

if (i==1 , i==4 , j==1 , j==9)

printf("*");

else

printf(" ");

printf("\n");

2. Input a number, if it >=0, calculate its square root, else print “invalid number”.

#include<stdio.h>

#include<math.h>

main()

{
double a;

printf("Nhap mot so:");

scanf("%lf",&a);

if (a>=0){

printf("Can bac hai cua %lf bang %lf",a,sqrt(a));

else

printf("Gia tri khong phu hop");

3. Input 3 numbers and print out the max and min values

#include <stdio.h>

main()

float a,b,c,min,max;

printf("Nhap 3 so a,b,c:");

scanf("%f%f%f", &a, &b, &c);

min=max=a;

if (b>max)

max=b;

if (c>max)

max=c;

printf("So lon nhat la %f", max);

if (b<min);

min=b;

if (c<min);

min=c;

printf("So be nhat la %f", min);

}
4. Input 2 number and print out the power of them(a b)

#include <stdio.h>

#include <math.h>

main()

double a,b, luythua;

printf("Nhap hai so:\n");

scanf("%lf%lf",&a,&b);

if (a<=0 && b<=0)

printf("Loi gia tri\n");

else {

luythua = pow(a,b);

printf("Luy thua cua %lf voi %lf la %lf",a,b,luythua);

5. Input a character and change it into upper case if it is in lower case.

#include<stdio.h>

main()

char c;

printf("Nhap mot ky tu:");

c=getchar();

if (c>='a' && c <= "z")

c=c-32;

printf("Ky tu da duoc doi la:");

putchar(c);
}

#include<stdio.h>

main()

int arr[100][100];

int m,n,t,min;

printf("Nhap so hang:");

scanf("%d",&n);

printf("Nhap so cot:");

scanf("%d",&m);

while (m>20||m<0||n>20||n<0)

printf("Nhap so hang:");

scanf("%d",&n);

printf("Nhap so cot:");

scanf("%d",&m);

for (int i=0;i<n;i++)

for (int j=0;j<m;j++)

printf("[%d][%d]=",i,j);

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

}
t=0;

min=arr[0][0];

for (int i=0;i<n;i++)

for (int j=0;j<m;j++)

if (arr[i][j]<min)

min=arr[i][j];

for (int i=0;i<n;i++)

for (int j=0;j<m;j++)

if (arr[i][j]==min)

t=t+1;

printf("So lan xuat hien cua min la:%d",t);

}
#include <stdio.h>

#include <stdlib.h>

double sum(int n) {

double s = 0;

for (int i = 1; i <= n; i++) {

int k = 0;

double den = 0;

// check the number is odd or even to start with 1 or 0

if (i % 2 != 0) {

k = 1;

// find denominator

for (int j = k; j <= i; j += 2) {

den += j;

// change denominator into negative number if i is even

if (i % 2 == 0) {

den *= -1;

// add to sum

s += i / den;

return s;
}

int main() {

int n;

printf("Input n: ");

scanf("%d", &n);

printf("S = %f", sum(n));

return 0;

You might also like