3. The digits are in alphabetical order in English.
// Print prime number series. class prime { void main () { int i = 1; int C = 0; int n = 1; int X = 0; while (X != 1000) { if ( n % i n ) { C = 0; n++ ; i = 0; } } i++ ; } } }
#include<iostream> using namespace std; int main() { cout << "Fibonacci sequence up to 100... int f1 = 0; int f2 = 1; cout << f1 << endl; while (f2<100) { cout << f2 << endl; int next = f1 + f2; f1 = f2; f2 = next; } }
int max (int a, int b) { return a>b?a:b; } int max3(int a, int b, int c) { return max(max(a,b),c);}
Random numbers can be generated using the Math.random() function. For example, the following statements is used to create a random number 0 and 34. int random= (int)(Math.random()*34);
int maxNum = 1000; for(int i = 0; i <= maxNum; i += 2) { // Java solution System.out.println(i); // C solution printf("%d\n", i); }
//program to find the fibonnacci series of n numbers. #include <stdio.h> void fibo(int); void main() { int iLimit; printf("Enter the number till which the fibonnacci series should be printed."); scanf("%d",&iLimit); fibo(iLimit); } void fibo(int iLimitnum) { int inum1,inum2,inum3; int iadd; inum1=0; inum2=1; int i; printf("0 "); for (i=0; ;i++) { iadd=inum1+inum2; inum1=inum2; inum2=iadd; if(inum1 > iLimitnum) break; printf("%d ", inum1); } }
//C program to find the factorial of a given number using functions #include<stdio.h> #include<conio.h> int fact(int); void main() { int f,t; clrscr(); printf("\nEnter any number:"); scanf("%d",&f); t=fact(f); printf("1=%d",t); getch(); } int fact(int fa) { int i,fac=1,t; for(i=fa;i>=2;i--) { // TO print the series printf("%dx",i); fac=i*fac; } return fac; }
main(){int n, first = 0, second = 1, next, c;printf("Enter the number of terms\n");scanf("%d",&n);printf("First %d terms of Fibonacci series are :-\n",n);for ( c = 0 ; c < n ; c++ ){if ( c
Math.h doesn't containing the round function. Use the following, int round(double number) { return (number >= 0) ? (int)(number + 0.5) : (int)(number - 0.5); }
First find the largest of two numbers, then compare that with the third number: int max (int a, int b) { return a>b?a:b; } int max_of_three (int a, int b, int c) { return max(max(a,b),c); }
int a = 3; int b = 7; int c; c = a + b;
int x; //first number int y; //second number int z = x*y;