Showing posts with label Display. Show all posts
Showing posts with label Display. Show all posts

DISPLAY SOURCE CODE AS OUTPUT IN C PROGRAM

How To DISPLAY SOURCE CODE AS OUTPUT IN C PROGRAM.

#include<stdio.h>
int main(){
    FILE *p;
    char ch;
    p=fopen("raja.c","r");
    while((ch=getc(p))!=-1)
         putchar(ch);
    fclose(p);
    return 0;
}

C Program To Display The Number In A Specific Formats

How to write a C Program to display the number in a specific formats in C Programming Language ?


Solution For C Program :

/*C Program To Display The Number In A Specific Formats*/

#include<stdio.h>
void main()
{
int r, s, n, key;
printf("\nEnter the Value of n : ");
scanf("%d", &n);
key = 1;
for(r = 1; r <= n; r++)
{
for(s = 1; s <= r; s++)
printf("%3d", key++);
printf("\n");
}
}

You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Program that Display a IBM Logo

How to write a C program that Display a IBM Logo in C Programming Language ?

This IBM Logo Program -- A C Program that Display a IBM Logo.

Solution:

  1. /*IBM Logo Program -- A program that Display a IBM Logo*/
  2. #include <stdio.h>
  3. #define RED     "\x1b[31m" // Colours for the logo to make it pretty!
  4. #define GREEN   "\x1b[32m"
  5. #define BLUE    "\x1b[34m"
  6. #define RESET   "\x1b[0m"
  7. int main()
  8. {
  9. /* IBM logo created by me, I use block characters */
  10. printf(GREEN"╔════════════════════════════════════════╗\n");
  11. printf(GREEN"║"BLUE" ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄   ▄▄▄▄▄       ▄▄▄▄▄"GREEN" ║\n");
  12. printf(GREEN"║"BLUE" ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄     ▄▄▄▄▄▄"GREEN" ║\n");
  13. printf(GREEN"║"BLUE"   ▄▄▄     ▄▄▄   ▄▄▄   ▄▄▄▄▄▄   ▄▄▄▄▄▄"GREEN"  ║\n");
  14. printf(GREEN"║"BLUE"   ▄▄▄     ▄▄▄▄▄▄▄▄    ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄"GREEN"  ║\n");
  15. printf(GREEN"║"BLUE"   ▄▄▄     ▄▄▄▄▄▄▄▄    ▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄"GREEN"  ║\n");
  16. printf(GREEN"║"BLUE"   ▄▄▄     ▄▄▄   ▄▄▄   ▄▄▄  ▄▄▄▄▄  ▄▄▄"GREEN"  ║\n");
  17. printf(GREEN"║"BLUE" ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄   ▄▄▄   ▄▄▄▄"GREEN" ║\n");
  18. printf(GREEN"║"BLUE" ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄   ▄▄▄▄    ▄    ▄▄▄▄"GREEN" ║\n");
  19. printf(GREEN"║"GREEN"                                      "GREEN"  ║\n");
  20. printf(GREEN"║"RED"    FreeBSD lenovo ThinkCentre M58p     "GREEN"║\n");
  21. printf(GREEN"║"RED"       BSD UNIX Operating System        "GREEN"║\n");
  22. printf(GREEN"╚════════════════════════════════════════╝"RESET"\n");
  23. }

LED ON OFF For One Sec/Count and Display on the Attached Serial Monitor

Turns on an LED on for one second, then off for one second, repeatedly. Counts and displays the count on the attached serial monitor

  1. /* Sketch uses 13,808 bytes (12%) of program storage space. Maximum is 108,000 bytes.
  2.    Global variables use 2,592 bytes of dynamic memory.
  3.   Turns on an LED on for one second, then off for one second, repeatedly.
  4.   Counts and displays the count on the attached serial monitor
  5.  */
  6. int n = 0;
  7. void setup() {                
  8.   // initialize the digital pin as an output.
  9.   pinMode(33, OUTPUT);
  10.   // Initialize virtual COM over USB on Maple Mini
  11.   Serial.begin(9600);  // BAUD has no effect on USB serial: placeholder for physical UART
  12.   // wait for serial monitor to be connected.
  13.   while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
  14.   {
  15.     digitalWrite(33,!digitalRead(33));// Turn the LED from off to on, or on to off
  16.     delay(100);         // fast blink
  17.   }
  18.   Serial.println("Blink LED & count Demo");
  19. }
  20. void loop() {
  21.   digitalWrite(33, HIGH);   // set the LED on
  22.   //delay(5);              // wait for a second
  23.   digitalWrite(33, LOW);    // set the LED off
  24.   Serial.print("Loop #: ");
  25.   n++;
  26.   Serial.println(n);
  27.    
  28.   //delay(5);              // wait
  29. }

Pre Order, Post order, In order Implement Binary Tree using linked list

How to write a C Program to implement Binary Tree using linked list. Display the three.. Search and item from the tree with proper message and traverse the tree in Pre Order, Post order and In order in C Programming Language ?


Solution:



/*
Write a program to implement Binary Tree using linked list. Display the three.. Search and item from
the tree with proper message and traverse the tree in
i) Pre Order
ii)Post order
iii) In order
*/

#include< stdio.h>
#include< conio.h>
#include< alloc.h>
struct bstree
{
int data;
struct bstree *lchild,*rchild;
};/*End of struct bstree*/
typedef struct bstree BST;
BST *root=NULL;
BST *create(BST *,int);
void inorder(BST *);
void preorder(BST *);
void postorder(BST *);
void search(BST *,int);
void main()
{
int ch;
int ele;
while(1)
{
clrscr();
printf("\nPress 1 For Insertion.");
printf("\nPress 2 For Inorder Traversal.");
printf("\nPress 3 For Preorder Traversal.");
printf("\nPress 4 For Postorder Traversal.");
printf("\nPress 5 For Search Item.");
printf("\nPress 6 For Exit.");
printf("\nEnter Your Choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter Element: ");
scanf("%d",&ele);
root=create(root,ele);
getch();
break;
case 2:
inorder(root);
getch();
break;
case 3:
preorder(root);
getch();
break;
case 4:
postorder(root);
getch();
break;
case 5:
printf("\nEnter Element To Be Searched: ");
scanf("%d",&ele);
search(root,ele);
getch();
break;
case 6:
exit(0);
break;
default:
printf("\nInvalid Choice... Try Again..");
getch();
}/*End of switch(ch)*/
}/*End of while(1)*/
}/*End of void main()*/
BST *create(BST *node,int x)
{
if(node==NULL)
{
node=(BST *)malloc(sizeof(BST));
node->lchild=NULL;
node->rchild=NULL;
node->data=x;
}/*End of if(node==NULL)*/
else if(xdata)
node->lchild=create(node->lchild,x);
else if(x>=node->data)
node->rchild=create(node->rchild,x);
return node;
}/*End of BST *create(BST *,int)*/
void inorder(BST *node)
{
if(node!=NULL)
{
inorder(node->lchild);
printf("%d ",node->data);
inorder(node->rchild);
}/*End of if(node!=NULL)*/
}/*End of void inorder(BST *)*/
void preorder(BST *node)
{
if(node!=NULL)
{
printf("%d ",node->data);
preorder(node->lchild);
preorder(node->rchild);
}/*End of if(node!=NULL)*/
}/*End of void preorder(BST *node)*/
void postorder(BST *node)
{
if(node!=NULL)
{
postorder(node->lchild);
postorder(node->rchild);
printf("%d ",node->data);
}/*End of if(node!=NULL)*/
}/*End of void postorder(BST *node)*/
void search(BST *node,int num)
{
if(node==NULL)
printf("\nThe Number Is Not Present.");
else if(node->data==num)
printf("\nElement Found.");
else if(node->data>num)
search(node->lchild,num);
else
search(node->rchild,num);
}/*End of void search(BST *node,int num)*/

C Program to accept n numbers & store all prime numbers in an array & display this result

How to write a C Program to accept n numbers & store all prime numbers in an array & display this result in C Programming Language ?


Solution:
/*C Program to accept n numbers & store all prime numbers in an array & display this result*/
#include<stdio.h>
#include<conio.h>
  void main()
{
  int a[10],i,n;
  clrscr();
  printf("\nEnter the n number: ");
  scanf("%d",&n);
  printf("\nEnter the numbers: ");
  for(i=0;i<=n;i++)
{
  scanf("%d",&a[i]);
}
  printf("\nThe Prime Number is: ");
  for(i=1;i<=n;i++)
{
  if(a[i]%2==1)
{
  printf("\t%d",a[i]);
}
}
  getch();
}

//OUTPUT:
//Enter the n number: 4

//Enter the numbers: 1
//2
//3
//4
//5

//The Prime Number is: 3 5

Create Two Singly Linked List Perform Differences Display It C Program

How to write a c program to create two singly linked list and perform differencer of two list and display it in C Programming Language ?

Solution:
/*write a c program to create two singly linked list and perform
differences of two list and display it*/
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node
{
int data;
struct node *next;
}*start1=NULL,*start2=NULL,*q1,*q2,*temp1,*temp2;
int n1=0,n2=0,*p1,*p2,i,j;
void create();
void display();
void differ();
void main()
{
clrscr();
create ();
display();
differ();
getch();
}
void create()
{
char ch='y';
while(ch=='y'||ch=='Y')
{
temp1=malloc(sizeof(struct node));
printf("\nenter the number for first L.L:-");
scanf("%d",&temp1->data);
temp1->next=NULL;
n1++;
if(start1==NULL)
start1=temp1;
else
{
q1=start1;
while(q1->next!=NULL)
{
q1=q1->next;
}
q1->next=temp1;
}
printf("\ndo you want to continue(Y|N):-");
scanf("\n%s",&ch);
}
ch='y';
while(ch=='y'||ch=='Y')
{
temp2=malloc(sizeof(struct node));
printf("\nenter the number for second L.L:-");
scanf("%d",&temp2->data);
temp2->next=NULL;
n2++;
if(start2==NULL)
start2=temp2;
else
{
q2=start2;
while(q2->next!=NULL)
{
q2=q2->next;
}
q2->next=temp2;
}
printf("\ndo you want to continue(Y|N):-");
scanf("\n%s",&ch);
}
}
void display()
{
p1=(int *)malloc(n1*sizeof(int));
p2=(int *)malloc(n2*sizeof(int));
if(start1==NULL)
printf("\nlinked list is empty");
else
{
printf("\nelement in first linked list are:-\n");
q1=start1;
for(i=0;i<n1;i++)
{
if(q1!=NULL)
{
*(p1+i)=q1->data;
printf("%d\n",*(p1+i));
q1=q1->next;
}
}
}
if(start2==NULL)
printf("\nlinked list is empty");
else
{
printf("\nelement in second linked list are:-\n");
q2=start2;
for(i=0;i<n2;i++)
{
if(q2!=NULL)
{
*(p2+i)=q2->data;
printf("%d\n",*(p2+i));
q2=q2->next;
}
}
}
}
void differ()
{
printf("\ndifferences of two sets are:-\n");
for(i=0;i<n1;i++)
{
for(j=0;j<n2;j++)
{
if(*(p1+i)==*(p2+j))
break;
}
if(j==n2)
printf("%d\n",*(p1+i));
}
}

Output:
/*
enter the number for first L.L:-4                                              
                                                                               
do you want to continue(Y|N):-y                                                
                                                                               
enter the number for first L.L:-8                                              
                                                                               
do you want to continue(Y|N):-y                                                
                                                                               
enter the number for first L.L:-1                                              
                                                                               
do you want to continue(Y|N):-y                                                
                                                                               
enter the number for first L.L:-6                                              
                                                                               
do you want to continue(Y|N):-n                                                
                                                                               
enter the number for second L.L:-4                                             
                                                                               
do you want to continue(Y|N):-y                                                

enter the number for second L.L:-1                                             
                                                                               
do you want to continue(Y|N):-n                                                
                                                                               
element in first linked list are:-                                             
4                                                                              
8                                                                              
1                                                                              
6                                                                              
                                                                               
element in second linked list are:-                                            
4                                                                              
1                                                                              
                                                                               
differences of two sets are:-                                                  
8
6
*/