Home > Back-end >  Introduction to C
Introduction to C

Time:04-23

Judge a number n can be divided exactly by 3 and 5 at the same time:
 # include 
Int main () {
int n;
Printf (" please enter a number: ");
The scanf (" % d ", & amp; N);
If (n % 3==0 & amp; & N % 5==0) {
Printf (" % d can also be divided exactly by 3 and 5 ", n);
}
The else {
Printf (" % d cannot be divided exactly by 3 and 5 "at the same time, n);
}
return 0;
}

Two idA, B are respectively 2, 3, 2, 3 first swaps to B, A:
 # include 
Int main () {
Int A=2;
Int B=3;
Int C;
C=B;
B=A;
A=C.
Printf (" A=% d, B=% d ", A, B);
return 0;
}

The prime number between 100-200 output:
 # include 
Int main () {
int n=0;
For (n=100; N & lt;=200; N++) {
int i=0;
For (I=2; I & lt;=n - 1; I++) {
If I==0) (n % {
break;
}
}
If (I & gt;=n) {
Printf (" % d \ n ", n);
}
}
return 0;
}

Number 3 a, b, c, demand and output them in size order:
 # include 
Int main () {
Int a, b, c, n;
Printf (" please enter the number 3: ");
The scanf (" % d, % d, % d ", & amp; A, & amp; B, & amp; C);

If (a & lt; B) {
N=b; B=a; A=n;
}
If (a & lt; C) {
N=c; c=a; A=n;
}
If (b & lt; C) {
N=c; C=b; B=n;
}
Printf (" % d, % d, % d ", a, b, c);

return 0;
}

In turn 10 number input, that output the largest number:
 # include 
Int main () {
int i;
Int num [10].
Int Max;
Printf (" please enter the number 10: ");
for(i=0; I & lt; 10; I++)
The scanf (" % d ", & amp; Num [I]);
For (I=0, Max num=[0]. I & lt; 10; I++)
Max num=[I] & gt; Max? Num [I] : Max;
Printf (" Max=% d \ n ", Max).
return 0;
}

For 1 + 2 + 3 +... + 100:
 # include 
Int main () {
int i;
int sum=0;
for(i=0; I & lt;=100; + + I) {
Sum=sum + I;
}
printf("sum=%d",sum);
return 0;
}

CodePudding user response:

 # include 
Int main () {
int n=0;
For (n=100; N & lt;=200; N++) {
int i=0;
For (I=2; I * I & lt; n; I++) {
If I==0) (n % {
break;
}
}
If (I & gt;=n) {
Printf (" % d \ n ", n);
}
}
return 0;
}

For your reference ~



 # include 
Int main () {
int i;
Int num [10].
Int Max;
Printf (" please enter the number 10: ");
for(i=0; I & lt; 10; I++)
The scanf (" % d ", & amp; Num [I]);
For (I=1, Max num=[0]. I & lt; 10; I++)//I starting from 1
If (Max & lt; Num [I])
Max num=[I];
//Max num=[I] & gt; Max? Num [I] : Max;
Printf (" Max=% d \ n ", Max).
return 0;
}

For your reference ~
  • Related