Third time job

Source: Internet
Author: User

1. Character judgment

Enter a character to determine if it is lowercase letter output its corresponding uppercase letter, if it is uppercase letters output its corresponding lowercase, if the digital output number itself, if it is a space, output "space", if not the case, output "other".

#include <stdio.h>intMain () {CharA; printf ("Enter a character:"); scanf ("%c",&a); if(a>='A'&&a<'Z') {a=a+ +; printf ("%c", a); }    Else if(a>='a'&&a<='Z') {a=a- +; printf ("%c", a); }    Else if(a>='0'&&a<='9') {printf ("%c", a); }    Else if(a==' ') {printf ("Space"); }    Else{printf (" Other"); }    return 0; } 

2. Age issues

Enter a student's birthday (year: Month: Day), and enter the current date (year: Month: Day) to calculate the actual age (years) of the birth.

#include <stdio.h>intMain () {intA,b,c,d,e,f,x,y; printf ("Enter your birthday:"); scanf (" %d%d%d",&a,&b,&c); printf ("Enter today's date"); scanf (" %d%d%d",&d,&e,&f); if(e>=b&&f>=c) {x=d-A; printf ("%d", x); }    Else{x=d-A; Y=x-1; printf ("%d", y); }    return 0;}

3 Judging the triangle type

Enter three integers to determine the type of triangle (equilateral triangle, isosceles triangle, isosceles right triangle, right triangle, general triangles, and non-triangles)

#include <stdio.h>intMain () {intA,b,c; printf ("Enter a three integer"); scanf (" %d%d%d",&a,&b,&c); if(a*a+b*b==c*c| | b*b+c*c==a*a| | a*a+c*c==b*b) {if(a==b&&b!=c| | a==c&&b!=c| | b==c&&a!=b) {printf ("isosceles Right Triangle"); }            Else{printf ("Right Triangle"); }    }    Else if(a==b&&b==c) {printf ("equilateral triangle"); }    Else if(a==b&&b!=c| | a==c&&b!=c| | b==c&&a!=b) {printf ("isosceles Triangle"); }    Else if(a+b>=c&&a+c>=b&&b+c>=a) {printf ("General Triangles"); }    Else{printf ("not a triangle ."); }      return 0;}

4 See commodity guess Price games

#include <stdio.h>#include<stdlib.h>#include<time.h>intMain () {intb;    Srand (Time (NULL)); printf ("guess the price of a product"); scanf ("%d",&a); b=rand ()% -; if(a==b) {printf ("guess right."); }    Else if(a>b) {printf ("big, the actual price is%d", B); }    Else{printf ("small, real price is%d\n", B); }    return 0;}

Additional question: Bug eating apple problem

You bought a box of n apples, unfortunately, when you bought it, you got into a bug in the box. Insects can eat an apple every x hours, assuming that the worm does not eat another one before eating an apple, how many complete apples do you have after y hours?

  Enter N,x and y (all integers) to output the remaining number of apples. Test data: 10 4 9 5 3 16
#include <stdio.h>intMain () {intN,x,y,a; printf ("Enter values for n,x and y, respectively"); scanf (" %d%d%d",&n,&x,&y); if(n>y/x&&y%x==0) {a=n-y/x; printf ("%d apples left .", a); }     Else if(n>y/x&&y%x!=0) {a=n-y/x-1; printf ("%d full apples left", a); }    Else{printf ("There is no complete apple left."); }    return 0; }

Knowledge Point Summary: Mastering character data (character constants and variables, string constants, input and output formats for character data and input-output functions)

Using random numbers, learning to use time to generate random numbers;

Applying a multi-if statement

Experimental summary: Pay attention to the correct spelling of the word;

Each if corresponds to an else, if and else use {}; behind each sentence; , if not added;

Calculate the size of the day of the year considering the age;

Char defines only one character, including spaces;

Lowercase letters 32 larger than uppercase letters

Third time job

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.