
妙趣编程
超翔之逸
可关注超翔之逸微信公众号哦!!!
展开
-
SQL10 用where过滤空值练习
描述题目:现在运营想要对用户的年龄分布开展分析,在分析时想要剔除没有获取到年龄的用户,请你取出所有年龄值不为空的用户的设备ID,性别,年龄,学校的信息。用where过滤空值练习_牛客题霸_牛客网题解:select device_id,gender,age,university from user_profile where age is not null;...原创 2022-05-25 09:33:02 · 272 阅读 · 0 评论 -
如何用Java实现九九乘法表
public class Test1 { public static void main(String[] args) { for (int i = 1; i <= 9; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + "*" + i + "=" + (i * j) + " "); } Syste.原创 2022-02-24 22:43:22 · 278 阅读 · 0 评论 -
c和C++求梯形的面积程序
#include<iostream>#include<math.h>using namespace std;void main(){ int a, b, c, s; cout << "please enter a,b,c:" << endl; cin >> a >> b >> c; s = (a + b) * c / 2; cout << "s="<<s; }#include原创 2020-11-28 11:12:08 · 3622 阅读 · 0 评论 -
Elevector
#include<cstdio>int main(){ int n,total=0,now=0,to; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&to); if(to>now){ total+=((to-now)*6); }else{ total+=((now-to)*4);...原创 2021-09-23 00:04:28 · 102 阅读 · 0 评论 -
通过函数调用来交换变量值的经典例子
#include<stdio.h>void swap1(int x, int y), swap2(int* px, int* py), swap3(int* px, int* py);int main(void){ int a = 1, b = 2; int* pa = &a, * pb = &b; swap1(a, b); printf("After calling swap1:a=%d b=%d\n", a, b); a =..原创 2021-08-21 18:37:21 · 204 阅读 · 0 评论 -
用字符串处理函数处理字符串
#include<stdio.h>#include<string.h>int main(){ int i; char sx[80],smin[80]; scanf("%s",sx); strcpy(smin,sx); for(i=1;i<5;i++){ scanf("%s",sx); if(strcmp(sx,smin)<0) strcpy(smin,sx); } ..原创 2021-08-21 18:10:52 · 110 阅读 · 0 评论 -
用字符串处理函数处理数字
#include<stdio.h>#include<string.h>int main(){ int i; char sx[80],smin[80]; scanf("%s",sx); strcpy(smin,sx); for(i=1;i<5;i++){ scanf("%s",sx); if(strcmp(sx,smin)<0) strcpy(smin,sx); } ..原创 2021-08-21 18:07:51 · 112 阅读 · 0 评论 -
任意个整数求和
#include<stdio.h>#include<stdlib.h>int main(){ int n,sum,i,*p; printf("Enter n:"); scanf("%d",&n); if((p=(int *)calloc(n,sizeof(int)))==NULL){ printf("Not able to allocate memory.\n"); exit(1); } ..原创 2021-08-21 18:05:03 · 291 阅读 · 0 评论 -
/分数化简和加减乘除
//分数化简Fraction reduction(Fraction result){ if(result.down<0){ result.up=-result.up; result.down=-result.down; } if(result.up==0){ result.down=1; }else{ int d=gcd(abs(result.up),abs(result.down)); .原创 2021-08-12 21:29:34 · 121 阅读 · 0 评论 -
查找元素算法
#include<stdio.h>const int maxn=210;int a[maxn];int main(){ int n,x; while(scanf("%d",&n)!=EOF){ for(int i=0;i<n;i++){ scanf("%d",&a[i]); } scanf("%d",&x); int k;...原创 2021-08-09 12:36:34 · 125 阅读 · 0 评论 -
//计算1+2+3+...+n
#include<stdio.h>int main(){ int i,n,sum; printf("Enter n:"); scanf("%d",&n); sum=0; for(i=1;i<=n;i++){ sum=sum+i; } printf("Some of the numbers from 1 to %d is %d\n",n,sum);}#include<stdio.h>in..原创 2021-08-08 12:00:51 · 222 阅读 · 0 评论 -
//简单的猜数游戏
#include<stdio.h>int main(){ int mynumber=38; int yournumber; printf("Input your number:"); scanf("%d",&yournumber); if(yournumber=mynumber) printf("Ok!you are right!\n"); else if(yournumber>mynumber) pr..原创 2021-08-08 11:58:11 · 157 阅读 · 0 评论 -
//计算多分段函数
#include<stdio.h>int main(){ double x,y; printf("Enter x:"); scanf("%lf",&x); if(x<0){ y=0; } else if (x<=15) { y=4*x/3; } else { y=2.5*x-10.5; } printf("f(%.2f)=%...原创 2021-08-08 11:57:08 · 178 阅读 · 0 评论 -
//求解简单的四则运算表达式
#include<stdio.h>int main(){ double value1,value2; char op; printf("Type in an expression:"); scanf("%lf%c%lf",&value1,&op,&value2); if(op='+') printf("=%.2f\n",value1+value2); else if(op='-') printf("=..原创 2021-08-08 11:55:39 · 751 阅读 · 0 评论 -
//统计字符
#include<stdio.h>int main(){ int digit,letter,other; char ch; int i; digit=letter=other=0; printf("Enter 10 characters:"); for(i=1;i<=10;i++){ ch=getchar(); if((ch>='a'&&ch<='z')||(ch>='A..原创 2021-08-08 11:52:31 · 77 阅读 · 0 评论 -
指针的妙处
#include<stdio.h>void change(int *p){ *p=233;}int main(){ int a=3; printf("%d\n",a); int *p=&a; printf("%d\n", *p); printf("%d\n", a); change(p); printf("%d\n",a); return 0;}原创 2021-07-23 21:21:50 · 109 阅读 · 0 评论 -
C++解决给定一个整数数组,判断是否存在重复元素。 如果存在一值在数组中出现至少两次,函数返回 true 。如果数组中每个元素都不相同,则返回 false 。
class Solution {public: bool containsDuplicate(vector<int>& nums) { sort(nums.begin(), nums.end()); int n = nums.size(); for (int i = 0; i < n - 1; i++) { if (nums[i] == nums[i + 1]) { .原创 2021-05-25 23:50:53 · 1049 阅读 · 0 评论 -
给出三角形三边长,计算三角形面积
#include <cmath>#include <iostream>#include <stdexcept>using namespace std;//给出三角形三边长,计算三角形面积double area(double a, double b, double c) throw(invalid_argument) { //判断三角形边长是否为正 if (a <= 0 || b <= 0 || c <= 0) .原创 2021-05-24 23:44:55 · 454 阅读 · 0 评论 -
C++解决给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出
#include<iostream>#include<vector>using namespace std; int singleNumber(vector<int> & nums){ int res = 0; for (auto &i : nums) { res ^= i; } return res;} int main(){ int nums[11] = { 1, 5, 6, 3, 5, 2, 1, 8, 6, 3,.原创 2021-05-24 23:39:27 · 887 阅读 · 1 评论 -
重载构造函数示例
#include<iostream>using namespace std;class Box{ private: int height; int width; int length; public: Box(); Box(int h); Box(int h,int w); Box(int h,int w,int len); int Volume();};Box::Box(){ height=1.原创 2021-05-23 23:47:54 · 274 阅读 · 0 评论 -
类和对象编程实例
#include<iostream>#include <ctime>#include <ostream>#include <time.h>using namespace std;class clock{ public: void SetTime(int NewH,int NewM,int NewS); void ShowTime(); private: int Hour,Second,Minute;};..原创 2021-05-23 23:23:59 · 207 阅读 · 0 评论 -
数组
#include<stdio.h>int a[5]={7,2,9,10,3};void st(int *,int);int main(){int i;st(a,5);for(i=0;i<5;i++)printf("%4d",a[i]);printf("\n");return 0;}void st(int *b,int n){int i,m,t;if(n==1) return;m=0;for(i=1;i<n;i++)if(b[i]<b[m])原创 2021-02-16 20:25:14 · 113 阅读 · 0 评论 -
/*指针和数组及存储单元*/
#include<stdio.h>int main(){ double a[2],*p,*q; p=&a[0]; q=p+1; printf("%lld\n",q - p); printf("%d\n",(int)q-(int)p); return 0;}原创 2021-02-15 23:03:38 · 243 阅读 · 0 评论 -
/*分别使用数组和指针计算数组元素之和*/
#include<stdio.h>int main(){ int i,a[10],*p; long sum=0; printf("Enter 10 integers:"); for(i=0;i<10;i++) scanf("%d",&a[i]); for(i=0;i<10;i++) sum=sum+a[i]; printf("calculated by array,sum=%ld\n",sum);原创 2021-02-15 23:02:18 · 1049 阅读 · 0 评论 -
/*方阵转置*/
#include<stdio.h>int main(){ int i,j,n,t; int a[6][6]; printf("Enter n:"); scanf("%d",&n); for(i=0;i<n;i++) for(j=0;j<n;j++) a[i][j]=i*n+j+1; for(i=0;i<n;i++) for(j=0;j<n;j++)原创 2021-02-15 22:42:10 · 209 阅读 · 0 评论 -
/*进制转换*/
#include<stdio.h>int main(){ int i,j; char hexad[80],str[80]; long number; printf("Ennter a string:"); i=0; while((str[i]=getchar())!='#') i++; str[i]='\0'; j=0; for(i=0;str[i]!='\0';i++) if(str原创 2021-02-15 22:06:59 · 111 阅读 · 0 评论 -
/*输入正整数n,输出1!-n!的值。要求定义并调用含静态变量的函数fact_s(n)计算n!*/
#include<stdio.h>double fact_s(int n);int main(){ int i,n; printf("Input n:"); scanf("%d",&n); for(i=1;i<=n;i++) printf("%3d!=%.0f\n",i,fact_s(i)); return 0;} double fact_s(int n){ static double f=1; f=f*n;原创 2021-02-13 11:10:23 · 7266 阅读 · 3 评论 -
*判断奇偶数的函数*/
#include<stdio.h>int even(int n);int main(){ int i; printf("Enter n:"); scanf("%d",&n); i=even(n); printf("i=%d",i); return 0;}int even(int n){ if(n%2==0) return 1; else return 0;}原创 2021-02-13 11:09:19 · 676 阅读 · 0 评论 -
/*用格雷戈里公式计算圆周率的值,精确度为e*/
#include<stdio.h>#include<math.h>double funpi(double e);int main(){ double e,pi;printf("Enter e:");scanf("%lf",&e);pi=funpi(e);printf("pi=%f\n",pi);return 0;}double funpi(double){ int i,j; double item,sum; i=1;j=原创 2021-02-13 11:08:25 · 1230 阅读 · 0 评论 -
/*查找奥运五环的位置,用指针数组实现*/
#include<stdio.h>#include<string.h>int main(){ int i; char *color[5]={"red","yellow","blue","black","green"}; char str[20]; printf("Input a color:"); scanf("%s",&str); for(i=0;i<5;i++) if(strcmp(str,color[i原创 2021-02-13 11:07:29 · 587 阅读 · 0 评论 -
/*解密藏头诗,用指针数组实现*/
#include<stdio.h>int main(){ int i; char* poem[4]={"一叶轻舟向东流"," "," "," "}; char mean[10]; for(i=0;i<4;i++){ mean[2*i]=*(poem[i]); mean[2*i+1]=*(poem[i]+1); } mean[2*i]='\0'; printf("%s",mean); retu原创 2021-02-13 11:06:25 · 1234 阅读 · 0 评论 -
/*用动态分配内存方法处理多个字符串的输入*/
#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){ int i,n=0; char *color[20],str[15]; printf("Please input some words about color:\n"); scanf("%s",str); while(str[0]!='#'){ color[n]=( char*)m原创 2021-02-13 11:05:32 · 328 阅读 · 0 评论 -
/*显示所有的命令行参数*/
#include<stdio.h>int main(int agrc,char*agrv[]){ int k; for(k=1;k<agrc;k++) printf("%s",argv[k]); printf("\n"); return 0;}原创 2021-02-13 11:04:18 · 297 阅读 · 0 评论 -
/*查找字符串中的字符位置(指针作为函数返回值的示例)*/
#include<stdio.h>char *match(char *s,char ch);int main(){ char ch,str[80],*p=NULL; printf("please input the string:\n"); scanf("%s",&str); getchar(); ch=getchar(); if((p=match(str,ch))!=NULL) printf("%s\n",p); e原创 2021-02-13 11:03:01 · 438 阅读 · 0 评论 -
/*计算数值积分(函数指针作为函数参数示例*/
#include<stdio.h>#include<math.h>double calc(double(*funp)(double),double a,double b);double f1(double x),f2(double x);int main(){ double result; double(*funp)(double); result=calc(f1,0.0,1.0); printf("1:result=%.4f\n",res原创 2021-02-13 11:00:31 · 281 阅读 · 1 评论 -
/*判断字符串是否为回文*/
#include <stdio.h>int main(){int k, i;char line[80];printf(“Enter a string:”);k = 0;while (line[k] = getchar() != ‘\n’)k++;line[k] = ‘\0’;/判断字符串line是否为回文/i = 0;k = [k - 1];while (i < k){if (line[i] != line[k])break;i++;k–;}if (原创 2021-02-12 10:57:52 · 205 阅读 · 0 评论 -
/*大小写英文字母转换*/
#include<stdio.h>int main(){ char ch; printf("input characters:"); ch=getchar(); while(ch!='\n'){ if(ch>='A'&&ch<='Z') ch=ch-'A'+'a'; else if(ch>='a'&&ch<='z') ch=ch-'a'+'A原创 2021-02-12 10:46:27 · 162 阅读 · 0 评论 -
/*统计字符串中数字字符的个数*/
#include<stdio.h>int main(){ int count,i; char str[80]; printf("Enter a string:"); i=0; while((str[i]=getchar()!='\n')) i++; str[i]='\0'; count=0; for(i=0;str[i]!='\0';i++) if(str[i]<='9'&&str[i]&g原创 2021-02-12 10:43:52 · 367 阅读 · 0 评论 -
/*提取字符并转换*/
#include<stdio.h>int main(){ int i,number; char str[10]; printf("Enter a string:"); i=0; while((str[i]=getchar())!='\n') i++; str[i]='\0'; number=0; for(i=0;str[i]!='\0';i++) if(str[i]>='0'&&str[原创 2021-02-12 10:41:48 · 166 阅读 · 0 评论 -
/*统计字符*/
#include<stdio.h>int main(){ int digit,letter,other; char ch; int i; digit=letter=other=0; printf("Enter n characters:"); for(i=1;i<=n;i++){ ch=getchar(); if((ch>'a'&&ch<'z')||(ch>'A'&原创 2021-02-10 13:21:35 · 101 阅读 · 0 评论