c语言编程计算(a*b)%c c语言编程:计算 a / b
c\u8bed\u8a00\u7f16\u7a0b\u8ba1\u7b97(a*b)%cint a,b,c;scanf("%d%d%d",&a,&b,&c);printf("%d",a*b%c);
#include int main(){ int a,b,c; do{ scanf("%d%d", &a,&b); fflush(stdin); }while(a10000||b>10000); if(b==0)printf("Division by zero.\n"); else { c = a/b; printf("%d\n", c); } return 0;}
直接二分幂取模,so easy!#include<stdio.h>
int pow_mod(int a,int b,int c)
{
int t;
if(b==0)
return 1;
if(b==1)
return a%c;
t=pow(a,b/2,c);
t=t*t%c;
if(b&1==1)
t=t*a%c;
return t;
}
int main()
{
int a,b,c;
while(scanf("%d%d%d",&a,&b,&c)!=EOF)
{
printf("%d\n",pow_mod(a,b,c));
}
return 0;
}
应该就是这样,现打的,没调试,应该过的了,要不行就把int改成__int64
大数问题,只能改变算法 ,主要思想就是将数字转换为字符,字符串处理就简单了。
#include<stdio.h>
main()
{
int a,b,c,s,h;
printf("输入abc:") //输入数据
scanf("%d%d%d",&a&b&c)
s=a*b;//计算
h=s%c;
printf("(a*b)%c=%d",h);//输出结果
}
这个应该属于大数的范畴,可以考虑改下算法 ;主要思想就是讲数字转换为字符来处理
#include<stdio.h>
#include<stdlib.h>
void main()
{
__int64 a,b,c;
while(scanf("%I64d %I64d %I64d",&a,&b,&c)!=EOF)
{
printf("%I64d %I64d %I64d\n",a,b,c);
printf("%I64d\n",((a%c)*(b%c))%c);
}
}
绛旓細绋嬪簭濡備笅:include <stdio.h> include <stdlib.h> int main(int argc, char *argv[]){ int a,b;scanf("%d %d",&a,&b);printf("%d",a+b);system("PAUSE");return 0;} C璇█缂栧啓绠鍗曠▼搴忓叿浣撴搷浣滄楠:1銆佸ご鏂囦欢锛氬熀鏈兘浼氬甫鏈変笁涓ご鏂囦欢锛岃繖鏄紪璇戠郴缁熻嚜甯︾殑澶存枃浠讹紝鎴戜滑涓鑸兘浼氫娇鐢ㄥ埌...
绛旓細灏辨暟瀛︿笂鏉ヨ涓鏍 1/a/b/c = ((1/a)/b)/c = 1/(a*b*c)浣嗘槸鍦╟閲岄潰绮剧‘搴︿笂浼氬嚭鐜颁笉鍚岀粨鏋 姣斿閮芥槸int 100/200/0.001 = (100/200)/0.0001 = 0/0.0001 = 0 浣嗘槸100/(200*0.001) = 100/0.2 = 500
绛旓細scanf()鏄C璇█涓殑涓涓緭鍏ュ嚱鏁般備笌printf鍑芥暟涓鏍凤紝閮借澹版槑鍦ㄥご鏂囦欢stdio.h閲岋紝鍥犳鍦ㄤ娇鐢╯canf鍑芥暟鏃惰鍔犱笂#include <stdio.h>銆傦紙鍦ㄦ湁涓浜涘疄鐜颁腑锛宲rintf鍑芥暟涓巗canf鍑芥暟鍦ㄤ娇鐢ㄦ椂鍙互涓嶄娇鐢ㄩ缂栬瘧鍛戒护#include <stdio.h>銆傦級鍑芥暟 scanf() 鏄牸寮忚緭鍏ュ嚱鏁帮紝鍗虫寜鐢ㄦ埛鎸囧畾鐨勬牸寮忎粠閿洏涓婃妸鏁版嵁杈撳叆...
绛旓細妤间笂绋嬪簭閿欎簡锛屽緱涓嶄簡姝g‘鐨勭粨鏋滐紒灏戜簡涓琛屼唬鐮侊紒搴旓紱include<stdio.h> void main(){ int a,b,c,min;printf("璇蜂换鎰忚緭鍏ヤ笁涓暣鏁帮細")scanf("%d%d%d",&a,&b,&c);if(a>=b)min=b;else min=a;if(min>c)min=c;printf("%d\n",min);} ...
绛旓細if(a == 0 && b == 0 && c == 0)printf("鏃犵┓瑙n");d = b*b - 4*a*c;if(d < 0)printf("鏃犺В\n");else if(d == 0){ x1 = x2 = -b/(2*a);printf("涓涓В锛 %lf\n",x1);else{ if(a == 0)printf("鏂圭▼涓轰竴娆℃柟绋嬶紒瑙d负%lf\n",(-c)/b);else{ x1...
绛旓細缂栧啓涓涓C绋嬪簭锛岃繍琛屾椂杈撳叆a,b,c涓変釜鍊硷紝杈撳嚭鍏朵腑鍊兼渶澶ц呯殑姝ラ锛1銆侀鍏堣緭鍏ヤ笁涓暟锛屾眰涓変釜鏁颁腑鐨勬渶澶у include<stdio.h> int main(){ int max(int x,int y,int z); int a,b,c,m; scanf("%d,%d,%d",&a,&b,&c); m=max(a,b,c); printf("the max numb...
绛旓細浠g爜淇敼濡備笅锛歩nclude<stdio.h>main(){int a,b,c,d;printf("璇疯緭鍏3涓暣鏁癨n");scanf("%d,%d,%d",&a,&b,&c);//d=a+b*c:d=a+b*c;printf("璁$畻缁撴灉: %d\n",d);}
绛旓細double a,b,c,disc;printf("璇疯緭鍏,b,c鐨勫硷細");scanf("%lf %lf %lf",&a,&b,&c);if(a==0) //涓鍏冧簩娆℃柟绋嬩簩娆¢」绯绘暟涓嶄负0 { printf("data error\n");} else { disc=b*b-4*a*c;if(disc>0)root2(a,b,disc);else if(disc==0)root1(a,b);else root0();} ...
绛旓細include <stdio.h>int main(void){ void output(int num[][3]); int i, j; int a[3][3], b[3][3], c[3][3]; puts("璇疯緭鍏ョ煩闃礱 : "); for (i = 0; i < 3; ++i) { for (j = 0; j < 3; ++j) scanf("%d", a[i] + j); } puts("璇疯緭鍏ョ煩闃礲 : ...
绛旓細鎶鏈瓑绾BCD瀵瑰簲涓涓皟鏁寸郴鏁帮紝杩欐槸涓缁勬湁鍏宠仈鐨勫父閲忥紝閫傚悎鐢ㄦ灇涓俱備笅闈㈡槸浠g爜锛屽伐璧勬垜鐢ㄧ殑鏄暣鍨嬶紝璁$畻绯绘暟鏄暣闄わ紝闇瑕佹诞鐐规暟锛岃嚜琛屼慨鏀圭被鍨嬨傚憳宸ヤ汉鏁颁慨鏀瑰父閲廝N锛屾垜娴嬭瘯鐢3涓憳宸ャ俰nclude<stdio.h> define PN 3//鍛樺伐鏁伴噺 enum tLevel{ A = 110, B= 120, C = 130, D = 140};//鎶鏈...