Tags » C Program

PATTERN with no.s 1

PATTERN:

5 4 3 2 1
4 3 2 1
3 2 1
2 1
1

C SOURCE CODE:

#include<stdio.h>
#include<conio.h>

void main()
{
int i,j,n;
printf("\n Enter no. 24 more words
Simple

PATTERN (*) 2

PATTERN:

      *
    *   *
  *   *   *  
*   *   *   *

C SOURCE CODE:

#include<stdio.h>
#include<conio.h>

void main()
{ 
int i, n, j;   
printf("Enter the number of rows \n"); 
scanf("%d",&n);   
for (i = 0; i < n; i++) 
{ 
for (j = 0; j <= (n - i - 2); j++) 
printf(" ");   
for (j = 0 ; j <= i; j++) 
{
printf("* ");
}   
printf("\n"); 
} 
getch();
}   

Simple

PATTERN (*) 1

PATTERN:


*
* *
* * *
* * * *

C SOURCE CODE:

#include<stdio.h>
#include<conio.h>
void main() y
{ 
int n, i, j;   
printf("Enter the number of rows\n"); 
scanf("%d", &n);   
for (i = 1; i<= n; i++) 
{ 
for (j= 1; j<= i; j++) 
{ 
printf("*    "); ; 
} 
printf("\n"); 
}
getch();
} 14 more words
Simple

POWER USING RECURSION

C SOURCE CODE:

#include<stdio.h>
#include<conio.h>
long power (int, int);
void main()
{ 
int p, n;
long a;
printf("Enter a number: ");
scanf("%d", &n);
printf("Enter the power: ");
scanf("%d", &p);
a = power(n, p);
printf("%d^%d = %ld", n, p, a);
getch();
} 
long power (int num, int p)
{ 
if (p!=0)
return (num * power(num, p - 1));
else
return 1;
}
Simple

LCM USING RECURSION

C SOURCE CODE:

#include <stdio.h>
#include <conio.h>

int lcm(int a, int b)
{
static int common = 1;  
if (common % a == 0 && common % b == 0) 
{ 
return common; 
} 
common++; 
lcm(a, b);
}

void main()
{ 
int x,y,l; 
printf("Enter two numbers: "); 
scanf("%d%d", &x, &y); 
l = lcm(x, y); 
printf("The LCM of %d and %d is %d\n", x, y, l); 
getch();
}
Simple

PRINT NUMBERS WITHOUT LOOP

C SOURCE CODE:


#include<stdio.h> #include<conio.h> void printno(int a,int n) { printf("%d\t",a); if(iprintno(++a,n); } void main() { int n; printf("\n Enter the max limit to print:"); scanf("%d",&n); printf("\nNumbers upto %d :\n",n); printno(1,n); getch(); }
Simple

SWAPPING NUMBERS using call by reference

In Call by reference method, the function is called by sending reference (address) of the variable in the function call statement. All the changes are done directly in the memory of passed variable. 112 more words

Simple