Second experiment Report of C language

Source: Internet
Author: User

11-1 local maxima of the matrix

Given m line n column integer Matrix a, if a Non-boundary elements [is larger than the next 4 elements, then the element [is the local maximum value of the matrix. The subject requires the full local maxima of the given matrix and its location.

#include <stdio.h>
int main ()
{
int m,n;
scanf ("%d%d", &m, &n);
int A[m][n], I, J;
for (i = 0; i < m; i++) {
for (j = 0; J < N; j + +) {
scanf ("%d", &a[i][j]);
}
}
int flag = 0;
for (i = 1; i < m-1; i++) {
for (j = 1; j < N-1; J + +) {
if (A[i][j] > A[i][j-1] && a[i][j] > a[i][j+1] && a[i][j] > A[i-1][j] && a[i][j] > a[i+ 1][j]) {
printf ("%d%d%d\n", A[i][j], i+1, j+1);
flag = 1; } } }
if (flag = = 0) {
printf ("None%d%d", M, N);
}

return 0; }

Design ideas: By defining a two-bit array to store function values, it is worth noting the position of the maximum in the array and determining whether the condition is complete.

12-4 String Letter Case Conversion

The subject requires the program, to a "#" end of the string, its lowercase letters all converted to uppercase, all uppercase letters to lowercase letters, other characters do not change output.

#include <stdio.h>
int main ()
{
int i=1;
Char A;
while (i>0)
{
scanf ("%c", &a);
if (a!= ' # ')
{
if (a<=90&&a>=65)
{
printf ("%c", a+32);
}
else if (a>=97&&a<=122)
{
printf ("%c", a-32);
}
Else
{
printf ("%c", a);
}

}
Else
{
i=0;
}
}

return 0;
}

Design ideas: The use of ASCII code table order, that is, the difference between the uppercase and lowercase letters 32 compiled code implementation.

13-5 judging a palindrome string

The need to write a function to determine whether a given string of characters is a "palindrome". The so-called "palindrome" refers to both reading and reading the same string. such as "Xyzyx" and "Xyzzyx" are palindrome.

#include <iostream>
using namespace Std;
int fun (int., int high, char *str, int length)
{
if (length = = 0 | | length = = 1)
return 1;
if (Str[low]! = Str[high])
return 0;
Return Fun (low+1, high-1, str, length-2);
}
int main ()
{
Char str[]= "AAABDAAA";
int length = strlen (str);
cout << Fun (0, length-1, str, length) << Endl;
return 0;
}

Design ideas: Pay attention to the details of the topic, using recursive method to achieve.

14-2 deleting characters

The subject requires implementing a simple function that deletes a specified character from a string.

#include <stdio.h>
#include <string.h>
#define MAXN 20

void Delchar (Charchar *str, char c);

int main ()
{
Char str[maxn]= "Happy New Year", C;

scanf ("%c", &c);
Delchar (str, c);
printf ("%s\n", str);

return 0;
}

void Delchar (Charchar *str, char c) {
int I,j,len;

len = strlen (str);
printf ("Len =%d\n", Len);

for (i=0;i<len;i++) {
if (str[i]==c) {
for (j=i;j<len;j++)
STR[J]=STR[J+1];
}
}
str[j]= ' + ';
}

Design ideas: Create a new array to store, using the method of deleting characters.

15-1 splitting the integer and fractional parts of a real number

A simple function that requires the realization of an integer and fractional part of a split real number

void Splitfloat (float x, int *intpart, float *fracpart)
{
int *k;
float *j;
int m;
float N;
M=x;
N=x-m;
k=&m;
j=&n;
*intpart=*k;
*fracpart=*j;
}

Experiment thanks: Read the topic consciousness, the consciousness provides the condition, with the pointer to implement the code together.

C Language Second experiment report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.