Here is the program to find the average of unlimited numbers:
program:
#include <stdio.h>
#include <stdlib.h>float averageByAsking()
{
int N, i;
printf(“Enter how many number do you wanted the average of: “);
scanf(“%d”, &N);
float sumbag[N], Average, AverageSum = 0;
for(i=0; i<N; i++){
printf(“Enter the %d number: “, i+1);
scanf(“%f”, &sumbag[i]);
AverageSum = AverageSum + sumbag[i];
}
Average = AverageSum / N;
printf(“\nThe average of entered numbers is: %.3f”, Average);
}int main()
{
averageByAsking();
return 0;
}result:
Enter how many number do you wanted the average of: 5
Enter your 1 number: 1
Enter your 2 number: 2
Enter your 3 number: 3
Enter your 4 number: 4
Enter your 5 number: 5
The average of entered number is: 3
thanks you very much….
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define SIZE 5
int main()
{
int i, flat = 1;
int arr[SIZE] = {1,2,3,2,1};
for(i=0; i < SIZE/2; i++){
if(arr[i] != arr[SIZE-1-i]){
flag = 0;
break;
}
}
if(flag == 1){
printf(“The array is a pailndrome\n\n”);
}
else if (flag == 0){
printf(“The array is not a plaindrome\n\n”);
}
return 0;
}
Therefore, you can use this code as opensource anywhere to calculate pailndrome worldwide.
This is easy to calculate but you need to apply some logic only here….
Thanks you very much…
#include <stdio.h>
#include <stdlib.h>
void findMinMax(int num1, int num2, int *pMax, int *pMin)
{
if(num1>num2)
{
*pMin = num2;
*pMax = num1;
}
else
{
*pMin = num1;
*pMax = num2;
}
}
int main(void)
{
int a,b;
printf(“Enter the value of a: “);
scanf(“%d”, &a);
printf(“Enter the value of b: “);
scanf(“%d”, &b);
int min, max;
findMinMax(a, b, &max, &min);
printf(“max between %d adn %d = %d \n”, a, b, max);
printf(“min between %d and %d = %d \n”, a, b, min);
return 0;
}
In this way, you can get the address of each value of array in c programming language and note the format string and symbol to print the address mr unknown:
#include <stdio.h>
#include <stdlib.h>
#define ROW 4
#define COL 4
int main()
{
int mat[ROW][COL];
int i, j;
for(i=0; i<ROW; i++){
for(j=0; j<COL; j++){
printf(“Enter the value of row %d column %d: “, i, j);
scanf(“%d”, &mat[i][j]);
}
}
printf(“\n\nYour array is here: \n\n”);
for(i=0; i<ROW; i++){
for(j=0; j<COL; j++){
printf(“%4d”, mat[i][j]);
}
printf(“\n”);
}
printf(“\n\nNow getting the memory address of each values of arrays:\n\n”);
for(i=0; i<ROW; i++){
for(j=0; j<COL; j++){
printf(“Address of mat[%d][%d] = %lu\n”, i, j, &mat[i][j]);
}
}
return 0;
}
Thanks you so much….
#include <stdio.h>
#include <stdlib.h>
#define N 10
int main(void){
int myArray[N];
int i, myIndex;
myIndex = 0;
for(i = 0; i < N; i++){
printf(“Enter value %d: “, i + 1);
scanf(“%d”, &myArray[i]);
}
printf(“\n Numbers in arrays are: “);
for(i = 0; i < N; i++){
printf(“ %d”, myArray[i]);
}
printf(“\n\n”);
for(i = 1; i < (N — 1); i++){
if(myArray[i] == myArray[i — 1] * myArray[i + 1]){
myIndex = i;
printf(“Array in the index of %d having number %d has good neighbour\n”, myIndex, myArray[i]);
}
else if(myArray[i] != myArray[i — 1] * myArray[i + 1]){
myIndex = i;
printf(“Array in the index of %d having number %d has not good neighbour\n”, myIndex, myArray[i]);
}
}
return 0;
}
This is the best way of calculating the good neighbors in c programming
Thanks you very much