# C language examination on computer operation question bank (basic) (Reference)

Posted by davidguz on Thu, 18 Jun 2020 08:23:53 +0200

Here are the possible code problems (Fundamentals) in the C language test:

(if you like it, please share it with your friends! Thank you

1. Find the total number of numbers between 300-800 that can be divided by 3 or 5.

```# include <stdio.h>

int main()
{
int i, s = 0;
for (i=300;i<=800;i++)
{
if (i%3==0||i%5==0)
s++;
}
printf("%d\n", s);

return 0;
}

```

2. Input a decimal number and output the corresponding octal and hexadecimal numbers. (output three lines, the first line is octal number, the second line is hexadecimal number, hexadecimal letters take lowercase characters, and the last line is empty)

```# include <stdio.h>

int main()
{
int i;
scanf("%d", &i);
printf("%o\n%x\n", i, i);

return 0;
}

```

3. Enter two positive integers m and n to find the maximum common divisor and the minimum common multiple. (input positive integers are separated by spaces, output two lines, the first line is the maximum common divisor, and the second line is the minimum common multiple)

```# include <stdio.h>
int main()
{
int m, n, x, y, z;
scanf("%d %d", &x, &y);
m = x;
n = y;
while (y!=0)
{
z = x%y;
x = y;
y = z;
}
printf("%d\n%d\n", x, m*n/x);

return 0;
}

```

4. Enter an integer n (1 < = n < = 10), then enter n integers, save them in the array, then enter an integer m, and output the subscript of m in the array. If not, output "Not present!". For example:
Input:
5
45 12 75 36 98
12
Output:
1

```# include <stdio.h>

int main()
{
int i, n, m, k, a;
scanf("%d", &n);
for (i=0;i<n;i++)
scanf("%d", &a[i]);
scanf("%d", &m);
for (i=0;i<n;i++)
{
k = i;
if (m==a[i])
{
printf("%d\n", i);
break;
}
}
if (k==n-1&&a[n-1]!=m)
printf("Not present!\n");

return 0;
}

```

5. Use the loop statement to implement the following figure. (pay attention to the overall position of the figure)
*

```Insert a code slice here
```
```# include <stdio.h>

int main()
{
int i, j, k;
for (i=1;i<=4;i++)
{
for (j=1;j<=4-i;j++)
printf(" ");
for (k=1;k<=2*i-1;k++)
printf("*");
printf("\n");
}

return 0;
}
```

6. Using recursive function, for a given integer 5, output its factorial.

```# include <stdio.h>
int fun(int n)
{
int s;
if (n==1)
return 1;
else
s  = n * fun(n-1);
return s;
}
int main()
{   int fun(int n);
int n = 5;
printf("%d\n",fun(5));

return 0;
}

```

7. Programming calculation 123 + 345 + 567 + +Value of 99100101.

```# include <stdio.h>

int main()
{
int i, s = 0;
for (i=1;i<101;i+=2)
s+=i * (i+1) * (i+2);
printf("%d\n", s);
return 0;
}

```

8. Use the loop statement to implement the following figure. (pay attention to the overall position of the figure)

```# include <stdio.h>

int main()
{
int i, j, k;
for (i=1;i<=4;i++)
{
for (j=1;j<=4-i;j++)
printf(" ");
for (k=1;k<=9;k++)
printf("*");
printf("\n");
}
return 0;
}

```

9. The monkey picked several peaches on the first day, ate half of them immediately, and then ate one more. The next morning I ate half of the rest of the peaches and another one, and then I ate half and one of the rest of the previous day every morning. When I wanted to eat again on the 10th morning, there was only one peach left. How many peaches do you want to pick on the first day?

```# include <stdio.h>
int main()
{
int i, s = 1;
for (i=1;i<10;i++)
s = (s+1) * 2;
printf("%d\n", s);

return 0;
}

```

10. ` between 2000 and 6000, find the total number of leap years.

```# include <stdio.h>

int main()
{
int i, s = 0;
for (i=2000;i<=6000;i++)
{
if((i%4==0&&i%100!=0)||(i%400==0))
s++;
}
printf("%d\n", s);

return 0;
}
```

11. Calculate and output the sum of integers between 1-200 that cannot be divided by 5.

```# include <stdio.h>

int main()
{
int i, s = 0;
for (i=1;i<=200;i++)
{
if (i%5!=0)
s+=i;
}
printf("%d\n", s);

return 0;
}
```

12. Obtain the number that can be divided by 3 in all four digits and the number that is equal to one hundred digits and the number that is odd in ten digits, and find their sum. (output each number that meets the requirements from small to large, each number occupies one line, and the last one is the sum of all the numbers that meet the requirements)

```# include <stdio.h>

int main()
{
int i, j, k, l, s = 0;
for (i=1000;i<10000;i++)
{
if (i%3==0)
{
j = i%1000/100;
k = i%1000%100/10;
l = i%1000%100%10;
if ((j==l)&&(k%2!=0))
{
s = s + i;
printf("%d\n", i);
}
}
}
printf("%d\n", s);

return 0;

}
```

13. If a number is exactly equal to the sum of its factors, it is called a "perfect number". For example, 6 = 1 + 2 + 3, find all the completions within 10000. (each line has a blank line at the end)

```# include <stdio.h>

int main()
{
int i, j, s;
for (i=3;i<=10000;i++)
{
s = 1;
for(j=2;j<i;j++)
if (i%j==0)
s = s + j;
if (i==s)
printf("%d\n", i);
}

return 0;
}
```

14: Write a program to output the graph according to the value of input n:
For example:
5
*

```*
```
```# include <stdio.h>

int main()
{
int i, j, k, a, b, c, n;
scanf("%d", &n);
for (i=1;i<=n;i++)
{
for (j=1;j<=n-i;j++)
printf(" ");
for (k=1;k<=2*i-1;k++)
printf("*");
printf("\n");
}
for (a=n-1;a>=1;a--)
{
for (b=1;b<=n-a;b++)
printf(" ");
for (c=1;c<=2*a-1;c++)
printf("*");
printf("\n");
}

return 0;
}

```

15. The element values in the array of integer array have been arranged in non decreasing order. There are seven elements in array array, which are 12, 23, 34, 45, 56, 67. When reading in an integer x to be inserted, insert x into the array, so that the elements in array remain in non decreasing order, and output the non decreasing arrangement (each number occupies 5 character width).

```# include <stdio.h>

int main()
{
int a={12,23,34,45,56,67}, x, i, j;
scanf("%d", &x);
for (i=0;i<=5;i++)
if (x<a[i])
{
for (j=6;j>=i+1;j--)
a = a[j-1];
a[i] = x;
break;
}
for (i=0;i<=6;i++)
printf("%d\t", a[i]);

return 0;
}
```

16. Write a program to determine whether an input integer is a prime number. If yes, output yes. If no, output No.

```# include <stdio.h>

int main()
{
int i, n, s = 0;
scanf("%d", &n);
for (i=2;i<n;i++)
{	if (n%i==0)
s++;
}
if(s==0)
printf("yes\n");
else
printf("no\n");

return 0;
}
```

17. Write a program to convert an input lowercase letter to its corresponding uppercase letter, and output the converted result.

```# include <stdio.h>

int main()
{
char i;
scanf("%c", &i);
i = i - 32;
printf("%c\n", i);

return 0;
}
```

18. Write a program, input a, b two values, the results from the order of large to small output two numbers separated by spaces.

```# include <stdio.h>

int main()
{
int a, b;
scanf("%d%d", &a,&b);
if (a>b)
printf("%d %d\n", a, b);
else
printf("%d %d\n", b, a);

return 0;
}
```

19. Write a program to output all prime numbers between 100-200 (one in a row).

```# include <stdio.h>

int main()
{
int i, j;
for (i=100;i<=200;i++)
{
for (j=2;j<i;j++)
{
if (i%j==0)
break;
}
if (i==j)
printf("%d\n", i);
}

return 0;
}
```

20. Write a program, input a, b two values, the results in order from small to large output.

```# include <stdio.h>
int main()
{
int a, b, t;
scanf("%d%d", &a, &b);
if (a>b)
{
t = a;
a = b;
b = t;
}
printf("%d %d\n", a, b);

return 0;
}
```

21. Output Jiu Jiu formula table (nine lines and nine columns, each format is 1 * 1 = 1, use tab to locate, nine lines and nine columns in total).

```# include <stdio.h>

int main()
{
int i, j;
for (i=1;i<=9;i++)
{
for (j=1;j<=i;j++)
printf("%d*%d=%d\t", j, i, i*j);
printf("\n");
}

return 0;
}

```

Topics: REST Programming C