• Join over 1.2 million students every month
  • Accelerate your learning by 29%
  • Unlimited access from just £6.99 per month
Page
  1. 1
    1
  2. 2
    2
  3. 3
    3
  4. 4
    4
  5. 5
    5
  6. 6
    6
  7. 7
    7
  8. 8
    8
  9. 9
    9
  10. 10
    10
  11. 11
    11
  12. 12
    12
  13. 13
    13
  14. 14
    14
  15. 15
    15
  16. 16
    16
  17. 17
    17
  18. 18
    18
  19. 19
    19
  20. 20
    20
  21. 21
    21
  22. 22
    22
  23. 23
    23
  24. 24
    24
  25. 25
    25
  26. 26
    26
  27. 27
    27
  28. 28
    28
  29. 29
    29
  30. 30
    30
  31. 31
    31

Entering Compiling and Running C Programs Problem 1 A program is required which prints all the odd numbers from 0 to 25.

Extracts from this document...

Introduction

Section A

Entering –Compiling and Running C Programs

Problem 1

A program is required which prints all the odd numbers from 0 to 25.

  /*****************

  *Problem Number 1*

  ******************/

        #include<stdio.h>

  void main()

  {

  int START=1;

  clrscr();

  do

        {

  printf("%d",START);

  START=START+2;

        }while(START<=25);

  getch();

  }

        Output  of the above program

image13.png

Modify the Program:

    *To print the even numbers between 0 and 25.

/*****************

  *Problem Number 1*

  ******************/

        #include<stdio.h>

  void main()

  {

  int START=2;

  clrscr();

  do

        {

  printf("%d",START);

  START=START+2;

        }while(START<25);

  getch();

  }

Output of the above program

image14.png

Modify the Program:

 *To print the even numbers between 0 and 50.

/*****************

  *Problem Number 1*

  ******************/

        #include<stdio.h>

  void main()

  {

  int START=2;

  clrscr();

  do

        {

  printf("%d                ",START);

  START=START+2;

        }while(START<=50);

  getch();

  }

Output of the above program

image25.png

Modify the Program:

         *To print the odd numbers between 15 and 35 along one line separated by a comma.

/*****************

  *Problem Number 1*

  ******************/

        #include<stdio.h>

  void main()

  {

  int START=15;

  clrscr();

  do

        {

  printf("%d,",START);

  START=START+2;

        }while(START<=35);

  getch();

  }

Output of the above program

image36.png

What is the purpose of the function getch()?

It gets the characters on the screen what the program  has to execute.

Problem 2

Write a program to determine if a given integer number  is dividable by 3

/******************

   *Problem Number 2*

   ******************/

  #include<stdio.h>

  void main()

  {

  int N;

  float R;

  clrscr();

  printf("Enter an integer Number: \n");

  scanf("%d",&N);

  R=N % 3;

  if(R==0)

           {

                printf("%d is dividable by 3. \n" ,N);

           }

  else

           {

                printf("%d is NOT dividable by 3. \n",N);

           }

  getch();

  }

Output of the above program

image44.png

Modify the Program to determine if a given number is dividable by 5.

       /******************

   *Problem Number 2*

   ******************/

  #include<stdio.h>

...read more.

Middle

      /******************

       *Problem Number 4*

       ******************

#include<stdio.h>

void main()

{

int I,N1,N2;

int s=0;

clrscr();

printf("Enter an integer N1: \n");

scanf("%d",&N1);

printf("Enter an integer N2 greater than N1: \n");

scanf("%d",&N2);

       i=N1;

do

   {

s=s+i;

i=i+1;

    }while(i<=N2);

      printf("The Sum=%d\n",s);

getch();

}

Output of the program

image22.png

In the above program user enters 10 instead of  N1 and enters 30 instead of  N2,so the sum  is

10+11+………..+30=420.

Write a program to continuously calculate the average of two numbers until the user requests to end.

       /******************

       *Problem Number 5*

       ******************

#include<stdio.h>

#include<string.h>

#include<graphics.h>

void main()

{

int N1,N2;

float Av;

char c;

do

   {

clrscr();

textcolor(CYAN);

cprintf("Enter an inter Number:");

scanf("%d",&N1);

cprintf("Enter another integer Number:");

scanf("%d",&N2);

Av=(float)(N1+N2)/2;

textcolor(GREEN);

cprintf("The Average of Numbers %d and %d=%f",N1,N2,Av);

gotoxy(20,22);

textcolor(YELLOW);

cprintf("Would you like to try again? <Y/N>:");

c=getch();

c=toupper(c);

    }

while(c=='Y');

textcolor(LIGHTGRAY);

}

Output of the program

image23.png

What are the functions of:

  • c=getch;

It gets the characters on the screen what the program  has to execute.

  • Gotoxy(20,22);

It determines  the location of the particular character/sentence on the screen, it means that the space

  and line number.

Section B: Writing Simple Programs

Problem 1

Write a program to print integer numbers from 10 down to 1 in steps of 1 on the screen.

#include<stdio.h>

void main(void)

{

int a=10;

clrscr();

do

    {

...read more.

Conclusion

printf("\n%d\n",n);

i++;

}

while(i<N);

getch();

}

Output of the program

image38.png

Problem 10

This program ,we design a simple 4-function calculator.

#include<stdio.h>

void main()

{

int a,b;

float S;

char op;

clrscr();

printf("Enter Expression as <a><op><b>=<Enter>:\n");

scanf("%d%c%d",&a,&op,&b);

switch(op)

          {

          case '+':

                                 {

                                 S=a+b;

                                 break;

                                 }

          case '-':

                                 {

                                 S=a-b;

                                 break;

                                 }

          case '/':

                                 {

                                 if(b==0)

                                                 {

                                                 printf("Divide By Zero Error!\n");

                                                 getch();

                                                 return;

                                                 }

                                   else

                                                 {

                                                 S=a/b;

                                                 }

                                                 break;

                                                 }

           case'*':

                                                 {

                                                 S=a*b;

                                                 break;

                                                 }

           default:

                                                 {

                                                 printf("Operation Unknown!\n");

                                                 break;

                                                 }

                                                }

 printf("\n\nResult:  %d %c %d = %.2f \n",a,op,b,S);

 getch();

}

Output of the program(operation ‘+’)

image39.png

Output of the program(operation ‘-’)

image40.png

Output of the program(operation ‘*’)

image41.png

Problem 11

Write a program to generate 10 random numbers between 1 and 15 and store them in a table.

#include<stdio.h>

#include<time.h>

#include<stdlib.h>

void main(void)

{

int T[10],N;

int j=0;

clrscr();

randomize();

do

   {

N=random(15)+1;

T[j]=N;

j=j+1;

   }

while(j<10);

j=0;

do

      {

printf("%d\n",T[j]);

j=j+1;

       }

while(j<10);

getch();

}

Output of the program

image42.png

Functions/Procedures in C.

Write a program to add two numbers together.

#include<stdio.h>

int ADD(int x,int y);

void PRINT(int x,int y,int z);

void main(void)

 {

int A=256,B=483,C;

C=ADD(A,B);

PRINT(A,B,C);

getch();

  }

int ADD(int x,int y)

       {

int s;

s=x+y;

return(s);

         }

void PRINT (int x,int y,int z)

            {

printf("The sum of %d and %d=%d\n",x,y,z);

             }

Output of the program

image43.png

...read more.

This student written piece of work is one of many that can be found in our University Degree Computer Science section.

Found what you're looking for?

  • Start learning 29% faster today
  • 150,000+ documents available
  • Just £6.99 a month

Not the one? Search for your essay title...
  • Join over 1.2 million students every month
  • Accelerate your learning by 29%
  • Unlimited access from just £6.99 per month

See related essaysSee related essays

Related University Degree Computer Science essays

  1. Traffic Light Simulation and Machine Code Program.

    Source Code The human readable program code typed into the computer. See executable code. SP The stack pointer register. In the RAM displays, the stack pointer is highlighted blue with yellow text. SR The status register. Stack An area of memory used for temporary storage according to the LIFO rule.

  2. The project explains various algorithms that are exercised to recognize the characters present on ...

    //******************************************************* // Global variables used by detection algorithm unsigned char I[480][720]; unsigned char I_temp[480][720]; int row_width, col_width; int start, stop; //******************************************************* /* * ======== main ======== */ void main() { printf("Video Preview Application\n"); fflush(stdout); /* Initialize BSL library to read jumper switches: */ EVMDM6437_DIP_init(); sysModuleRegs -> PINMUX0 &= (0x005482A3u); sysModuleRegs

  1. IP network design

    The monthly costs compare with those of a premium ADSL service, although there are also significant initial installation costs. Most suppliers will provide options to buy or lease the equipment. In some regions, e.g. Wales, there are two-way satellite subsidy schemes in operation for those in remote areas.

  2. So in order to understand what the main areas where organisation should be aware ...

    * TCP Reverse Ident Scanning The ident protocol (RFC 141316) is used to determine the owner username of a particular TCP connection by communicating with port. This involves opening a full TCP connection to the target machine port. The scanning method gives the attacker information that helps determine which server to attack.

  1. Assembly Program.

    I will explain this in greater detail later. Connections P1.0: MOTOR 1 P1.4: MOTOR 2 P1.1: MOTOR 1 P1.5: MOTOR 2 P1.2: MOTOR 1 P1.6: MOTOR 2 P1.3: MOTOR 1 P1.7: MOTOR 2 P3.0: RxD, FOR CONTROLS SENT TO THE MICROPROCESSER (pin 3)

  2. The purpose of this project is to discuss the issues associated with the deployment ...

    * Provide a rich application environment, which enables delivery of information and interactive services to digital mobile phones, pagers, personal digital assistants (PDAs) and other wireless devices. * Address unique characteristics of wireless devices. These devices have hardware factors (e.g.

  1. Cache-Enhanced Dynamic Movement-Based Location Management Schemes for 3G Cellular Networks.

    Basic Approaches of Location Management 26 2.5. Current Approaches in Location Update 28 2.5.1 Mobile Initiated Location Update Strategies 29 2.5.2 Prediction-based Location Update Schemes. 31 2.5.3 Profile-based Location Update Scheme 33 2.5.4 Protocol-based Location Update Scheme 34 2.6. Current approaches on Terminal Paging 35 2.7.Qualitative comparisons of the location management schemes 38 3.

  2. VoIP - Red, yellow or green light?

    This circuit must be set up before a conversation can be established and a dedicated path is issued for the entire duration of the call. Hence any idle time during the conversation is simply wasted bandwidth. In comparison, VoIP employs packet switching.

  • Over 160,000 pieces
    of student written work
  • Annotated by
    experienced teachers
  • Ideas and feedback to
    improve your own work