About:
|
#include <stdio.h> 大數
#include <string.h>
int main()
{
char A[50], B[50];
int i, N, sum[51]={0};
gets(A);
gets(B);
if(strlen(A) >= strlen(B))
N = strlen(A);
else
N = strlen(B);
for(i=0; i<N; i++)
{
if(i > (strlen(A)-1))
sum[i] = sum[i] + (int)B[strlen(B)-i-1]-48;
else if(i > (strlen(B)-1))
sum[i] = sum[i] + (int)A[strlen(A)-i-1]-48;
else
sum[i] = sum[i] + (int)A[strlen(A)-i-1]-96 + (int)B[strlen(B)-i-1];
if(sum[i] > 9)
{
sum[i] = sum[i] - 10;
sum[i+1] = sum[i+1] + 1;
}
}
if(sum[N] == 0)
N = N - 1;
for(i=N; i>=0; i--)
printf("%d", sum[i]);
return 0;
}
/////////////////////////////////////////
#include <stdio.h> GCD
#include <stdlib.h>
int gcd(int a, int b)
{
int rem;
while(b != 0)
{
rem = a % b;
a = b;
b = rem;
}
return a;
}
int main()
{
int a, b;
scanf("%d %d", &a, &b);
printf("%d", gcd(a, b));
return 0;
}
////////////////////////////////////////
#include<stdio.h> 考試5*5
int main(void)
{
int x[5][5];
int i, j,max,min;
float sum;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
scanf("%d",&x[i][j]);
}
}
for(i=0;i<5;i++)
{
sum=0;
for(j=0;j<5;j++)
{
sum+=x[i][j];
}
printf("Student %d\n",i+1);
printf("- Total score: %g\n",sum);
printf("- Average score: %g\n", sum/5);
}
for(j=0;j<5;j++)
{
sum=0;
max=0;
min=9999;
for(i=0; i<5; i++)
{
sum+=x[i][j];
if (x[i][j]>max)
max=x[i][j];
if (x[i][j]<min)
min=x[i][j];
}
printf("Quiz %d\n",j+1);
printf("- Average score: %g\n", sum/5);
printf("- High score: %d\n",max);
printf("- Low score: %d\n",min);
}
return 0;
}
//////////////////////////////////////////////////////////
#include <stdio.h> function prime number
int is_prime(int n)
{
int i,j=0;
for (i=1;i<=n;i++)
{
if (n%i==0)
j++;
}
if (j==2)
return 1;
else
return 0;
}
int main(void)
{
int n;
scanf("%d", &n);
if (is_prime(n)) // function return 1
printf("Prime");
else // function return 0
printf("Not prime");
return 0;
}
//////////////////////////////////////////////////////////
#include <stdio.h> GPA
float compute_GPA(char grades[100],int n)
{
float sum=0;
int c;
for(c=0;c<n;c++)
{
switch(grades[c])
{
case'A':
case'a':
sum+=4; break;
case'B':
case'b':
sum+=3; break;
case'C':
case'c':
sum+=2; break;
case'D':
case'd':
sum+=1; break;
}
}
return sum/n;
}
int main(void)
{
char G[100];
int n;
int c;
scanf("%d",&n);
for(c=0;c<n;c++)
scanf(" %c",&G[c]);
printf("%g",compute_GPA(G,n));
return 0;
}
////////////////////////////////////////////////////////
#include <stdio.h> 兩字串差異自原
#include <string.h>
#include <ctype.h>
int is_anagrams( char A[],char B[])
{
int c,n,i,j,x;
int D[26]={0},E[26]={0};
char C[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
for(i=0 ; i<26 ; i++)
{
for(j=0;j<strlen(A);j++)
{
if (C[i]==A[j] || tolower(C[i])==A[j])
D[i]++;
}
}
//////////////////////////////////////////////////////////
#include <stdio.h> selection_sort
void sort(int a[], int N)
{
if(N > 1)
{
int i, max = a[0], max_i=0, temp;
for(i=1; i<N; i++)
{
if(max < a[i])
{
max = a[i];
max_i = i;
}
}
temp = a[N-1];
a[N-1] = a[max_i];
a[max_i] = temp;
sort(a, N-1);
}
}
int main()
{
int N, i;
scanf("%d", &N);
int a[N];
for(i=0; i<N; i++)
scanf("%d", &a[i]);
sort(a, N);
for(i=0; i<N; i++)
printf("%d ", a[i]);
return 0;
}
/////////////////////////////////////////////////////////////
#include <stdio.h> 字串大寫變小寫
int a(char n)
{
if (n>=65&&n<=90)
return n+32;
else if (n>=97&&n<=122)
return n-32;
else
return n;
}
int main(void)
{
char n;
while (n!='\n')
{
scanf("%c",&n);
printf("%c",a(n));
}
return 0;
}
//////////////////////////////////////////////////////////
#include<stdio.h> 巴斯卡
void fun(int);
int main(void){
int in;
scanf("%d",&in);
if(in==0)
printf("0");
fun(in);
}
void fun(int n){
int buf[20]={1};
int i, j;
for(i=0;i<n;i++)
{
for(j=i;j>0;j--)
buf[j] = buf[j] + buf[j-1];
for(j=0;j<=i;j++)
{
printf("%d", buf[j]);
if(i != j)
printf(" ");
}
printf("\n");
}
}
/////////////////////////////////////////////////////////
#include <stdio.h> 日歷
int main()
{
int days, n;
int i, j=0;
while(scanf("%d%d", &days, &n) != EOF)
{
j = n - 1;
if(n != 1)
{
printf(" ");
}
for(i = 1; i < n-1; i++)
{
printf(" ");
}
for(i = 1; i <= days; i++)
{
if(j != 0)
{
printf(" ");
}
if(i < 10)
{
printf(" %d", i);
}
else
{
printf("%d", i);
}
j++;
if(j == 7)
{
printf("\n");
j = 0;
}
}
printf("\n");
}
return 0;
}
///////////////////////////////////////////
#include<stdio.h> 數字變英文
int main()
{
int a,z,y;
scanf("%d",&a);
z=a/10;
y=a-(10*z);
switch(a)
{
case 0 : printf("zero");
break;
}
if(a<0)
{
printf("negative ");
if(a<-10 && a>-20)
switch(a*(-1))
{
case 11 : printf("eleven");
break;
case 12 : printf("twelve ");
break;
case 13 : printf("thirteen ");
break;
case 14 : printf("fourteen ");
break;
case 15 : printf("fifteen ");
break;
case 16 : printf("sixteen ");
break;
case 17 : printf("seventeen");
break;
case 18 : printf("eighteen ");
break;
case 19 : printf("nineteen ");
break;
}
else
{
switch(z*(-1))
{
case 10 : printf("one hundred");
break;
case 9 : printf("ninety ");
break;
case 8 : printf("eighty ");
break;
case 7 : printf("seventy ");
break;
case 6 : printf("sixty ");
break;
case 5 : printf("fifty ");
break;
case 4 : printf("forty ");
break;
case 3 : printf("thirty ");
break;
case 2 : printf("twenty ");
break;
}
switch(y*(-1))
{
case 9 : printf("nine");
break;
case 8 : printf("eight");
break;
case 7 : printf("seven");
break;
case 6 : printf("six");
break;
case 5 : printf("five");
break;
case 4 : printf("four");
break;
case 3 : printf("three");
break;
case 2 : printf("two");
break;
case 1 : printf("one");
break;
}
}
}
else
{
if(a>10 && a<20)
swit
|