1、 display=t1+t2; t1=t2; t2=display; +count;%d+,display); return 0;结果输出: 10 0+1+1+2+3+5+8+13+21+34+也可以使用下面的源代码:/* Displaying Fibonacci series up to certain number entered by user. */ int t1=0, t2=1, display=0, num;Enter an integer:num); while(displaynum) 200 0+1+1+2+3+5+8+13+21+34+55+89+144+2、回文检查源代码:
2、/* C program to check whether a number is palindrome or not */ int n, reverse=0, rem,temp;, & temp=n; while(temp!=0) rem=temp%10; reverse=reverse*10+rem; temp/=10; /* Checking if number entered by user and its reverse number is equal. */ if(reverse=n) %d is a palindrome.,n); else%d is not a palindro
3、me. 1232112321 is a palindrome.3、质数检查注:1既不是质数也不是合数。/* C program to check whether a number is prime or not. */ int n, i, flag=0;Enter a positive integer: for(i=2;i=n/2;+i) if(n%i=0) flag=1; break; if (flag=0)%d is a prime number.%d is not a prime number. 2929 is a prime number.4、打印金字塔和三角形使用*建立三角形* *
4、* * * * * * * * * int i,j,rows;Enter the number of rows:rows); for(i=1;=rows; for(j=1;j=1;-i)用 * 打印金字塔 * * * * * * * * * * * * * * * * * * * * * * * * int i,space,rows,k=0; for(space=1;space=rows-i;+space) while(k!=2*i-1) +k; k=0;用 * 打印倒金字塔#include int rows,i,j,space;Enter number of rows: for(space=
5、0;rows-i; for(j=i;=2*i-1; for(j=0;i-1;5、简单的加减乘除计算器/* Source code to create a simple calculator for addition, subtraction, multiplication and division using switch.case statement in C programming. */# include char o; float num1,num2;Enter operator either + or - or * or divide :%co);Enter two operands
6、:%f%fnum1,&num2); switch(o) case +:%.1f + %.1f = %.1f,num1, num2, num1+num2);-%.1f - %.1f = %.1f,num1, num2, num1-num2);*%.1f * %.1f = %.1f,num1, num2, num1*num2);/%.1f / %.1f = %.1f,num1, num2, num1/num2); default: /* If operator is other than +, -, * or /, error message is shown */Error! operator
7、is not correct - 3.48.43.4 - 8.4 = -5.06、检查一个数能不能表示成两个质数之和int prime(int n); iint binary_decimal(int n);int decimal_binary(int n); int n;Instructions:1. Enter alphabet d to convert binary to decimal.n2. Enter alphabet b to convert decimal to binary.n if (c = | c = DEnter a binary number:%d in binary
8、= %d in decimal, n, binary_decimal(n);BEnter a decimal number:%d in decimal = %d in binary, n, decimal_binary(n);int decimal_binary(int n) /* Function to convert decimal to binary.*/ int rem, i=1, binary=0; while (n! rem=n%2; n/=2; binary+=rem*i; i*=10; return binary;int binary_decimal(int n) /* Fun
9、ction to convert binary to decimal.*/ int decimal=0, i=0, rem; rem = n%10; n/=10; decimal += rem*pow(2,i); +i; return decimal;9、使用多维数组实现两个矩阵的相加int main() int r,c,a100100,b100100,sum100100,i,j;Enter number of rows (between 1 and 100):r);Enter number of columns (between 1 and 100):nEnter elements of 1
10、st matrix:/* Storing elements of first matrix entered by user. */ for(i=0;r;c;Enter element a%d%d:,i+1,j+1);aij);/* Storing elements of second matrix entered by user. */Enter elements of 2nd matrix:bij);/*Adding Two matrices */ sumij=aij+bij;/* Displaying the resultant sum matrix. */nSum of two matr
11、ix is: nn,sumij); if(j=c-1)nn10、矩阵转置 int a1010, trans1010, r, c, i, j;Enter rows and column of matrix:%d %dr, &/* Storing element of matrix entered by user in array a. */nEnter elements of matrix: j +j)Enter elements a%d%d:/* Displaying the matrix a */nEntered Matrix: n,aij);/* Finding transpose of matrix a and storing it in array trans. */ transji=aij;/* Displaying the transpose,i.e, Displaying array trans. */nTranspose of Matrix:,transij); if(j=r-1)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1