• 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.

    Signed Numbers Numbers where the left most bit is the sign bit. Simulator Computer software that models reality in some way. Virtual reality aims to make the simulation so realistic that it seems real. Most simulations are designed to be useful rather than realistic.

  2. IP network design

    These capabilities are only made possible by the use of complex and advanced technologies which drive up the cost of associated equipment. However, SDH does provide supreme resilience and reliability levels and is expected to provide the transport infrastructure for worldwide telecommunications for the foreseeable future. 2.2 IP Addressing 2.2.1.

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

    This is what we wished for any kind of response to give away the existence of the system and the fact that the probed port is closed. If we send the SYN/ACK to an open port, it will ignore any such packet o FIN: The FIN scan uses the FIN packet as the probe.

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

    The use of Internet technologies is not new for WML, as WML1 is a fully conformant XML language in its own right. * Additional Services and Capabilities - The WAP specifications have had items that were neither part of the 'WAP Stack' nor the 'WAP Browser' but helped to enrich the environment defined in the WAP specifications.

  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. 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)

  1. 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.

  2. In order to determine the effectiveness of auditing programs in promoting energy savings, the ...

    It is calculated by 1- SSE . This reflects the true proportion of dependent variable is explained by the ?yi2 independent variables under non-constant models. r2 is always greater than R2 (*) . Although 0<r2<1, it's not comparable with R2 (as calculated on different basis). Therefore, comparing models based on R2 is sometimes difficult.

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