AllBestEssays.com - All Best Essays, Term Papers and Book Report
Search

C Programming - Write a Program That Inputs 4 Numbers and Calculates the Sum, Average and Product of All the Numbers

Essay by   •  May 3, 2016  •  Coursework  •  1,815 Words (8 Pages)  •  1,526 Views

Essay Preview: C Programming - Write a Program That Inputs 4 Numbers and Calculates the Sum, Average and Product of All the Numbers

Report this essay
Page 1 of 8

C PROGRAMS

PREPARED BY: -                                                        VERIFIED BY:-

NAME: Talha Rafiq                                               SIR MUHAMMAD YASIR
CLASS: XII SCI B1                                                       PAKISTAN URDU SCHOOL
ROLL NO.                                                                KINGDOM OF BAHRAIN
2014-2015

PROJECT PARTNERS:-

Salman Nawaz

Yousuf Salahuddin

Yasrab Jabbar

Teacher’s Signature

  1. WRITE A PROGRAM THAT INPUTS 4 NUMBERS AND CALCULATES THE SUM, AVERAGE   AND PRODUCT OF ALL THE
    NUMBERS.

#include

#include

main( )

{

int a,b,c,d,sum,avg,prod;

printf("enter the four numbers");

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

sum=a+b+c+d;

avg=sum/4;

prod=a*b*c*d;

printf("the sum is %d \n",sum);

printf("the average is  %d \n",avg);

printf("the product is %d \n",prod);

getch();

}

 Enter the four numbers , 2 ,4,5,6

OUTPUT

The sum is =17

The average is = 4.25

The Product is =240

  1. WRITE A PROGRAM THAT INPUTS BASE AND HEIGHT FROM THE USER AND CALCULATES AREA OF TRIANGLE BY USING THE (FORMULA AREA=12*BASE*HEIGHT)

#include

#include
void main()

{

int base,height,area;

printf(“enter the base and height “);

scanf(“%d%d”,&base,&height);

area= 0.5*base*height;

printf(“the area of triangle is %d “,area);

getch();

}

        

Enter the base and height 5,4

OUTPUT

The area of triangle is 10

3-WRITE A PROGRAM THAT INPUTS A NUMBER AND FINDS WHETHER IT IS EVEN OR ODD USING IF-ELSE STRUCTURE.

#include

#include

void main()

{

int num;

printf(“enter the number”);

scanf(“%d”,&num);

if(num%2==0)

printf(“the number is even %d“,num);

else

printf(“the number is odd %d”,num);

getch();

}

                             

Enter the number 3

OUTPUT

The number is even

4-WRITE A PROGRAM THAT INPUTS A NUMBER OF WEEKDAYS AD DISPLAYS THE NAME OF THE DAY USING SWITCH STATEMENT.

#include

#include

void main()

{

int num;

printf(“enter the number “);

scanf(“%d”,&num)

switch(num)
{

case 1:

printf(“SUNDAY”);

break;

case 2:

printf(“MONDAY”);                                                                 enter the number, 4

break;

case 3:

printf(“TUESDAY”);                                                                               OUTPUT

break;

case 4:

printf(“WEDNESDAY”);                                                                       WEDNESDAY

break;

case 5:

printf(“THURSDAY”);

break;

case 6:

printf(“FRIDAY”);

break;

case 7:

printf(“SATURDAY”);

break;

default :

printf(“enter correct number “);

}

getch();

}

5-        WRITE A PROGRAM THAT INPUTS A YEAR AND CHECK WHETHER IT IS A LEAP YEAR OR NOT USING IF-ELSE .

#include

#include

void  main()

{

int year;

printf(“enter the year “);

scanf(“%d”,&year);

if(year%4==0)

printf(“the year is a leap year %d”,year);

else

printf(“the year is a normal year %d”,year);

getch();

}

                 Enter the year ,2015

                   OUTPUT

The year is a normal year

6-WRITE A PROGRAM THAT DISPLAYS FIRST TEN NUMBERS AND THEIR AVERAGE USING DO..WHILE LOOP.

#include

#include

void main()

{

int sum=0, j,avg;

do

{

printf(“%d”,j);

j++;

sum=sum+j;

}while(j<=10);

avg=sum/10;

printf(“the average is %d”,avg);

getch();

}

OUTPUT

 

012345678910th average is 6

7-WRITE A PROGRAM THAT DISPLAYS THE FOLLOWING SHAPE USING NESTED LOOP

*

* *

* * *

* * * *

* * * * *

#include

#include

 main()

{

int i,j;                                                             OutPut

for(i=1 ; i<=5 ; i++)                                             *

...

...

Download as:   txt (9.6 Kb)   pdf (130.1 Kb)   docx (13.7 Kb)  
Continue for 7 more pages »
Only available on AllBestEssays.com