56. Add 'n' numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int n, sum=0, i, value;
clrscr();
printf("Enter total numbers you want to add : ");
scanf("%d", &n);
for (i=1; i<=n; i++)
{
printf("Enter number %d : ", i);
scanf("%d", &value);
sum = sum + value;
}
printf("Sum of entered numbers : %d", sum);
getch();
}
57. Add 'n' numbers using array.
#include<stdio.h>
#include<conio.h>
void main()
{
int n, sum = 0, i, array[100];
clrscr();
printf("Enter total numbers you want to add : ");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
printf("Enter number %d : ", i);
scanf("%d", &array[i]);
sum = sum + array[i];
}
printf("Sum : %d\n", sum);
getch();
}
58. Program to accept a number and add the digits of that number.
#include<stdio.h>
#include<conio.h>
void main()
{
int n, sum = 0, remainder;
clrscr();
printf("Enter the number : ");
scanf("%d", &n);
while (n != 0)
{
remainder = n % 10;
sum = sum + remainder;
n = n / 10;
}
printf("Sum of digits of entered number : %d", sum);
getch();
}
59. Program to accept a number and add the digits of that number using recursion.
#include<stdio.h>
#include<conio.h>
int add_digits(int);
void main()
{
int n, result;
clrscr();
printf("Enter a number : ");
scanf("%d", &n);
result = add_digits(n);
printf("Sum : %d", result);
getch();
}
int add_digits(int n)
{
static int sum = 0;
if (n == 0)
{
return 0;
}
sum = n % 10 + add_digits(n / 10);
return sum;
}
60. Average of numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int n, i;
float sum=0, x, avg;
clrscr();
printf("Enter total Numbers : ");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
printf("\nNumber %d : ", i );
scanf("%f", &x);
sum += x;
}
avg = sum / n;
printf("\nThe Average is : %0.2f", avg);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n, sum=0, i, value;
clrscr();
printf("Enter total numbers you want to add : ");
scanf("%d", &n);
for (i=1; i<=n; i++)
{
printf("Enter number %d : ", i);
scanf("%d", &value);
sum = sum + value;
}
printf("Sum of entered numbers : %d", sum);
getch();
}
57. Add 'n' numbers using array.
#include<stdio.h>
#include<conio.h>
void main()
{
int n, sum = 0, i, array[100];
clrscr();
printf("Enter total numbers you want to add : ");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
printf("Enter number %d : ", i);
scanf("%d", &array[i]);
sum = sum + array[i];
}
printf("Sum : %d\n", sum);
getch();
}
58. Program to accept a number and add the digits of that number.
#include<stdio.h>
#include<conio.h>
void main()
{
int n, sum = 0, remainder;
clrscr();
printf("Enter the number : ");
scanf("%d", &n);
while (n != 0)
{
remainder = n % 10;
sum = sum + remainder;
n = n / 10;
}
printf("Sum of digits of entered number : %d", sum);
getch();
}
59. Program to accept a number and add the digits of that number using recursion.
#include<stdio.h>
#include<conio.h>
int add_digits(int);
void main()
{
int n, result;
clrscr();
printf("Enter a number : ");
scanf("%d", &n);
result = add_digits(n);
printf("Sum : %d", result);
getch();
}
int add_digits(int n)
{
static int sum = 0;
if (n == 0)
{
return 0;
}
sum = n % 10 + add_digits(n / 10);
return sum;
}
60. Average of numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int n, i;
float sum=0, x, avg;
clrscr();
printf("Enter total Numbers : ");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
printf("\nNumber %d : ", i );
scanf("%f", &x);
sum += x;
}
avg = sum / n;
printf("\nThe Average is : %0.2f", avg);
getch();
}
0 comments:
Post a Comment