C Programming - Write a Program That Inputs 4 Numbers and Calculates the Sum, Average and Product of All the Numbers
Autor: Maryam • January 22, 2018 • 760 Words (4 Pages) • 652 Views
...
{ * *
for(j=1 ; j
printf(“*”); * * * *
printf(“\n”); * * * * *
}
getch();
}
8-WRITE A PROGRAM TO FIND THE SUM OF POSITIVE ODD NUMBERS AND THE PRODUCT OF POSITIVE EVEN NUMBERS LESS THAN OR EQUAL TO 14 USING FOR LOOP.
#include
#include
main()
{
int i , sumodd=0, prodeven=1;
for (i=1 ; i
{
sumodd=sumodd+i;
prodeven=prodeven*i;
if ( i%2==0)
printf(“sumodd is %d”,sumodd);
else
printf(“prodeven is %d” , prodeven);
}
getch();
}
OutPut
prodeven is 1
sumodd is 3
prodeven is 6
sumodd is 10
prodeven is 120
sumodd is 21
prodeven is 5040
sumodd is 36
prodeven is 362880
sumodd is 55
prodeven is 39916800
sumodd is 78
prodeven is 1932053504
sumodd is 105
9-WRITE A PROGRAM THAT GENERATES TABLE OF A GIVEN NUMBER USING WHILE LOOP.
#include
#include
#define clrscr()
main()
{
int j,prod,num;
j=1;
clrscr();
printf("enter the number to print its table \n");
scanf("%d",&num);
while(j
{
prod=num*j;
j++;
printf("%d*%d=%d\n",num,j,prod);
}
getch();
}
enter the number to print its table
5
OutPut
5*2=5
5*3=10
5*4=15
5*5=20
5*6=25
5*7=30
5*8=35
5*9=40
5*10=45
5*11=50
5*12=55
5*13=60
10- WRITE A PROGRAM THAT DISPLAYS THE ASCII CODE OF THE CHARACTER TYPED BY THE USER.
#include
#include
#define clrscr()
main()
{
char alpha;
clrscr();
printf("enter any character");
scanf("%c",&alpha);
printf("the ASCII code of %c is equal to %d",alpha,alpha);
getch();
}
Enter any character
A
OutPut
97
---------------------------------------------------------------
11- WRITE A PROGRAM THAT INPUTS AN INTEGER FROM THE USER. IT DISPLAYS THE SUM OF INTEGERS FOR EACH INTEGER FROM TO THE GIVEN NUMBER.
#include
#include
main()
{
int i,num,sum;
sum=0;
printf("enter the number \n");
scanf("%d",&num);
for ( i=1;i
{
sum=sum+i;
}
printf("the sum of above numbers is %d \n ",sum);
getch();
}
Enter the number
5
OutPut
The sum of above numbers is 15
---------------------------------------------------------------
12- WRITE A PROGRAM THAT PROMPTS THE USER TO
...