C Program to Print Number Pattern
Triangle of Numbers in C, C Program to print Number RightAngle, Pattern of Number in C
1
2 3
4 5 6
7 8 9 10
#include
#include
void main()
{
int i,j,n,a=1;
clrscr();
printf("enter the range\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",a);
a=a+1;
}
printf("\n");
}
getch();
}
Related Links :
Program to print fibonacci series in c language
Fibonacci series in C Programming, Fibonacci series printing in C, C assignment to print fibonacci series
#include "stdio.h"
#include "conio.h"
void main()
{
int a,b,c,i,n;
clrscr();
a=0;
b=1;
printf("\n Please enter n for how many times generate series");
scanf("%d",&n);
printf("\n FIBONACCI SERIES in C Language \n");
printf("\t%d\t%d",a,b);
for(i=0;i<n;i++)
{
c=a+b;
a=b;
b=c;
printf("\t%d",c);
}
getch();
}
Related Links :
c program to Find GCD of two number
Find G.C.D. of two numbers in C, C Assignment to find GCD of 2 numbers, Write a c program for finding gcd (greatest common divisor) of two given numbers
#include
int main ()
{
int x,y,m,i;
printf("Insert any two number: ");
scanf("%d%d",&x,&y);
if(x>y)
m=y;
else
m=x;
for (i=m;i>=l;i--)
{
if(x%i==0&&y%i==0)
{
printf("\nHCF of two number is : %d",i) ;
break;
}
}
return 0;
}
Related Links :
C program to find given number is prime or not
Prime Number Program in C, C assignment to find Prime Number
#include
#include
int main()
{
int num,i,count=0;
printf("Enter a number: ");
scanf("%d",&num);
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
count++;
break;
}
}
if(count==0 && num!= 1)
{
printf("%d is a prime number",num);
}
else
{
printf("%d is not a prime number",num);
}
getch();
return 0;
}
Related Links :
C program to swap a two value without using 3rd variable, arithmetic operator
#include
#include
void main()
{
int a,b;
clrscr();
printf("\n Enter Value For First Number : -");
scanf("%d",&a);
printf("\n Enter Value For Second Number: -");
scanf("%d",&b);
aA=bA=aA=b;
printf("\n\n First Number = %d",a);
printf("\n Second Number = %d",b);
getch();
}
Related Links :
C Program to calculate sum of an array elements using pointers
Addition of array using pointers in C, C example to add array using pointers, Pointers in C
#include
#include
void main()
{
int a[10];
int i,sum=0;
int *ptr;
printf("Please Enter 10 Array elements:\n");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
ptr = a; /* a=&a[0] assing array to pointer variable*/
for(i=0;i<10;i++)
{
sum = sum + *ptr; //*p=content pointed by 'ptr'
ptr++;
}
printf("\nThe sum of array elements is %d",sum);
/* Finally printing Sum of array elements using pointers */
}
Related Links :
C Program to Print Square of given Matrix
Square of Matrix in C , C Multidimensional Array Example to find Square of matrix, Matrix multiplication in C
#include
#include
#define MAX_ROWS 3
#define MAX_COLS 4
void print_square(int [ ] );
void main (void)
{
int row;
int num [MAX_ROWS][MAX_COLS] = {
{0,1,2,3},
{4,5,6,7},
{8,9,10,11}
};
for(row=0; row< MAX_ROWS; row++)
print_square(num[row]);
}
void print_square(int x[ ])
{
int col;
for (col = 0; col< MAX_COLS; col++)
printf ("%d\t", x[col] * x[col]);
printf("\n");
}
Related Links :
C Program to create triangle of ABCD
Pyramid of Characters in C | C Assignment to create right triangle of ABCD
#include
#include
void main()
{
int i,j;
clrscr();
for(i=65;i<=68;i++)
{
for(j=65;j<=i;j++)
{
printf("%c",j);
}
printf("\n");
}
getch();
}
Related Links :
C Program to Find Leap Year
C Assignment to Find given year leap year or not, Leap Year Program in C
#include
main()
{
int year;
clrscr();
printf("Enter a year to check if it is a leap year\n");
scanf("%d", &year);
if ( year%400 == 0)
printf("%d is a leap year.\n", year);
else if ( year%100 == 0)
printf("%d is not a leap year.\n", year);
else if ( year%4 == 0 )
printf("%d is a leap year.\n", year);
else
printf("%d is not a leap year.\n", year);
getch();
return 0;
}
Related Links :
Circular queue in Data Structure
The queue that we implemented using an array suffers from one limitation. In that implementation there is a possibility that the queue is reported as full (since rear has reached the end of the array), even though in actuality there might be empty slots at the beginning of the queue. To overcome this limitation we can implement the queue as a circular queue . Here as we go on adding elements to the queue and reach the end of the array, the next element is stored in the first slot of the array (provided it is free).
More clearly, suppose an array arr of n elements is used to implement a circular queue. Now if we go on adding elements to the queue we may reach arr(n-l). We cannot add any more elements to the queue since we have reached the end of the an-ay. Instead of reporting the queue as full, if some elements in the queue have been deleted then there might be empty slots at the beginning of the queue. In such a case these slots would be filled by new elements being added to the queue. In short just because we have reached the end of the array the queue would not be reported as full. The queue would be reported as full only when all the slots in the array stand occupied.
Related Links :
Queue as an array - Data Structure
Queue, being a linear data structure can be represented in various ways such as arrays and linked lists. Representing a queue as an array would have the same problem that we discussed in case of stacks. An array is a data structure that can store a fixed number of elements. The size of an array should be fixed before using it Queue, on the other hand keeps on changing as we remove elements from the front end or add new elements at the rear end. Declaring an array with a maximum size would solve this problem. The maximum size should be large enough for a queue to expand or shrink.
Related Links :
Stack as an array Data Structure
Stack contains an ordered collection of elements. An array is used to store ordered list of elements. Hence, it would be very easy to manage a stack if we represent it using an array. However, the problem with an array is that we are required to declare the size of the array before using it in a program. This means the size of an array should be fixed. Stack on the other hand does not have any fixed size. It keeps on changing, as the elements in stack are popped or pushed.
Though an array and a stack are totally different data structures, an array can be used to store the elements of a stack. We can declare the array with a maximum size large enough to manage a stack. As a result, the stack can grow or shrink within the space reserved for it.
Related Links :
C Program to show bubble sorting Numbers from random Array
bubble sorting Method Example in C | Sort Numbers using bubble sorting method | Random Number sorting using bubble sorting technique.
#include
#define MAX 10
int a[MAX];
int rand_seed=10;
int rand() /* returns random number between 0 and 32767.*/
{
rand_seed = rand_seed * 1103515245 +12345;
return (unsigned int)(rand_seed / 65536) % 32768;
}
void bubble_sort(int m)
{
int x,y,t;
for (x=0; x < m-1; x++)
for (y=0; y < m-x-1; y++)
if (a[y] > a[y+1])
{
t=a[y];
a[y]=a[y+1];
a[y+1]=t;
}
}
void main()
{
int i,t,x,y;
/* fill array */
for (i=0; i < MAX; i++)
{
a[i]=rand();
printf("%d\n",a[i]);
}
bubble_sort(MAX);
/* print sorted array */
printf("--------------------\n");
for (i=0; i < MAX; i++)
printf("%d\n",a[i]);
}
Related Links :
C Program to create Random Number Array & Sort it
Array fills an array with random numbers, sorts them using a bubble sort, and then displays the sorted list.
#include
#define MAX 10
int a[MAX];
int rand_seed=10;
int rand()
/* from K&R - produces a random number between 0 and 32767.*/
{
rand_seed = rand_seed * 1103515245 +12345;
return (unsigned int)(rand_seed / 65536) % 32768;
}
void main()
{
int i,t,x,y;
/* fill array */
for (i=0; i < MAX; i++)
{
a[i]=rand();
printf("%d\n",a[i]);
}
/* bubble sort the array */
for (x=0; x < MAX-1; x++)
for (y=0; y < MAX-x-1; y++)
if (a[y] > a[y+1])
{
t=a[y];
a[y]=a[y+1];
a[y+1]=t;
}
/* print sorted array */
printf("--------------------\n");
for (i=0; i < MAX; i++)
printf("%d\n",a[i]);
}
Related Links :
C Program to Reverse given number by Recursion
Reverse Digit using recursion | WAP to Reverse given Number in C Language
#include
int rev(int,int);
int main()
{
int a;
printf("Type a value : ");
scanf("%d",&a);
printf("Reverse: %d",rev(a,0));
return 0;
}
int rev(int i,int r)
{
if(i > 0)
return rev(i/10,(r*10)+(i%10));
return r;
}
Related Links :
C Programs to Count characters of file
Count characters in File, C Assignment to Calculate characters in given File in C
#include
int main()
{
FILE *fp;
char a[10];
long cnt=0;
int c;
printf("Enter file name : ");
gets(a);
if((fp=fopen(a,"r"))==NULL)
printf("File dosen't exist.");
else
{
while(1)
{
c=fgetc(fp);
if(feof(fp)) break;
cnt++;
}
printf("\nfile have %ld characters",cnt);
}
fclose(fp);
return 0;
}
Related Links :
Transpose the matrix In C
C Program to Transpose the matrix | Transpose the matrix in C Language | C Assignment to Transpose the matrix | Example of Multidimensional array of Transpose the matrix
#include
int main()
{
int a[4][4],i,j,b;
for(i=0;i<4;i++)
{
printf("\nEnter elements of %d row of Matrix: ",i+1);
for(j=0;j<4;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<4;i++)
{
for(j=i+1;j<4;j++)
{
b=a[i][j];
a[i][j]=a[j][i];
a[j][i]=b;
}
}
printf("\n Transposed Matrix:\n\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf("%4d",a[i][j]);
printf("\n");
}
return 0;
}
Related Links :
C Program to Convert File to upper case using command line arguments
Command Line Arguments in C | Passing Parameters From Command Line in C | Convert File to Uppercase | Capitalize File in C
#include
int main(int n,char *a[])
{
int c;
FILE *fr,*fw;
if(n!=3)
{
printf("Sorry..!! Invalid numbers of arguments.");
return 1;
}
if((fr=fopen(a[1],"r"))==NULL)
{
printf("File can't be open.");
return 1;
}
if((fw=fopen(a[2],"r+"))==NULL)
{
printf("File can't be open.");
fclose(fr);
return 1;
}
while(1)
{
c=fgetc(fr);
if(feof(fr)) break;
c=~c;
fputc(c,fw);
}
fclose(fr);
fclose(fw);
return 0;
Related Links :
Pattern of Numbers in C Language
Pyramid of Numbers in C, Triangle of Numbers in C
#include
#include
void main()
{
int i,j,n,k;
clrscr();
printf("enter the range\n");
scanf("%d",&n);
k=n+1;
for(i=1;i<=n;i++)
{
for(j=1,k=k-i;j<=i;j++)
{
printf("%d",k);
k++;
}
printf("\n");
}
getch();
}
enter the range
5
5
45
345
2345
12345
Related Links :
History Of C..
In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.
My 1st Program...
#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}
Next Step...
#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");
printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");
getch ();
}