Monday, 22 April 2019

c program to read age of 15 person and total baby age,school age and adult age

#include<stdio.h>
main()
{
int n,i,s1=0,s2=0,s3=0;
printf("Enter the age of 15 person:");
do
{
scanf("%d",&n);
if(n>=0&&n<=5)
s1=s1+n;
else if(n>=6&&n<=17)
s2=s2+n;
else
s3=s3+n;
i++;
}
while(i<=15);
printf("Total Babys age=%d\n",s1);
printf("Total school students age=%d\n",s2);
printf("Total adult age=%d",s3);
}

Tuesday, 16 April 2019

Average for 5 numbers

#include<stdio.h>
#define N   5
main()
{
float number,sum,count,avg;
sum=0;
count=0;
while(count<N)
{
    scanf("%f",&number);
    sum=sum+number;
    count=count+1;
}
avg=sum/count;
printf("Average=%f",avg);
}

Multification table by using array

#include<stdio.h>
#define ROWS    5
#define COLUMN  5
main()
{
int i,j,row,column,product[ROWS][COLUMN];
printf("MULTIFICATION TABLE\n\n");
printf("    ");
for(j=1;j<=COLUMN;j++)
printf("%4d",j);
printf("\n");
printf("-------------------------------------------\n");
for(i=1;i<=ROWS;i++)
{
row=i+1;
printf("%2d |",row);
for(j=i;j<=COLUMN;j++)
{
column=j;
product[i][j]=row*column;
printf("%4d",product[i][j]);
}
printf("\n");
}
}