Showing posts with label Table. Show all posts
Showing posts with label Table. Show all posts

C Program Array NxM Elements Geometric/Arithmetic

How to Write a C Program for numbering the product of all real numbers listed in the array NxM elements,  or function counting the arithmetic average of all the numbers listed in the array NxM Elemental, for counting the geometric mean NxM array elements and for counting the arithmetic average above the main diagonal in the table NxM elements in C Programming Language ?


//Napisać procedurę liczącą iloczyn wszystkich liczb rzeczywistych znajdujących się w tablicy NxM elementowej.

Write procedure for numbering the product of all real numbers listed in the array NxM elements.



void iloczyn (int tablica[N][M])
{
 int i,j,iloczyn=0;
for(i=0;i<N;i++)
    for(j=0;j<M;j++)
       iloczyn*=tablica[i][j];
printf("Iloczyn liczb w tablicy wynosi: ",iloczyn);
}

//Napisać procedurę lub funkcję liczącą średnią arytmetyczną wszystkich liczb znajdujących się w tablicy NxM elementowej.

Write a procedure or function counting the arithmetic average of all the numbers listed in the array NxM Elemental



float srednia_aryt(int tablica[N][M])
{
int i,j,suma=0;
for(i=0;i<N;i++)
    for(j=0;j<M;j++)
       suma+=tablica[i][j];
return suma/N*M;
}

 //Napisać procedurę liczącą średnią geometryczną w tablicy NxM elementowej.

//Write procedure for counting the geometric mean NxM array elements.



float srednia_geo(int tablica[N][M])
{
int i,j,iloczyn=0;
for(i=0;i<N;i++)
    for(j=0;j<M;j++)
       iloczyn*=tablica[i][j];
return pow(iloczyn,NxM);
}

   //Napisać procedurę liczącą średnią arytmetyczną ponad główną przekątna w tablicy NxM elementowej.

Write procedure for counting the arithmetic average above the main diagonal in the table NxM elements.



float srednia_aryt(int tablica[N][M])
{
int i,j,suma=0;
for(i=0;i<N;i++)
    for(j=0;j<M;j++)
       if(i<j)
         suma+=tablica[i][j];
return suma/N*M;
}

C Program To Print Table Horizontally

How to write a C Program To Print Table Horizontally in C Programming Language ?


Solution For C Program :

/*C Program To Print Table Horizontally.*/


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,num;
clrscr();
printf("Enter the no up to which you want table==>");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
for(j=1;j<=10;j++)
{
printf("%d\t",i*j);
}
printf("\n");
}
getch();
}


OUTPUT :
Enter the no up to which you want table==>5
1        2       3       4        5        6        7        8        9       10
2       4       6       8       10       12      14      16      18      20
3       6       9      12      15       18      21      24      27      30
4       8       12    16      20      24      28      32      36      40
5      10      15    20     25      30      35      40      45      50


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable



C Program To Generate Multiplication Table

How to write a C Program to generate Multiplication Table in C Programming Language ?


Solution For C Program:

/*C Program To Generate Multiplication Table*/

#include<stdio.h>
void main()
{
int num, ctr;
printf("\nEnter Number for the Table : ");
scanf("%d", &num);
printf("\nNow Printing the Table...\n");
for(ctr = 1; ctr <= 10; ctr++)
printf("%d\t*\t%d\t=\t%d\n", num, ctr, num * ctr);
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

Printing ASCII Table with Numbers and corresponding characters

How to write a C Program to Printing ASCII Table with Numbers and corresponding characters in C Programming Language ?

The following program prints the ASCII Table with the numbers from 0 to 255 and their corresponding equivalent characters in ASCII.

Write a program to print all the ASCII values and their equivalent characters using a while loop. The ASCII values vary from 0 to 255.

  1. #include<stdio.h>
  2. main()
  3. {
  4. int num;
  5.  
  6. printf("Printing ASCII values Table...\n\n");
  7.  
  8. num = 1;
  9.  
  10. while(num<=255)
  11.  
  12. {
  13.  
  14. printf("\nValue:%d = ASCII Character:%c", num, num); /*This change has been made as per the comment. Thank you anonymous Blog Viewer ... */
  15.  
  16. num++;
  17. }
  18.  
  19. printf("\n\nEND\n");
  20.  
  21. }

the program should have a char input declaration .. ie.. 
int num;
char c;
.
.
.
then, after the while loop 
printf("\n Value:%d= ASCII character:%c",num,c);
.. because the character variable in the above printf statement cannnot be "num" as it has been declared as the integer variable at the start of the program.

It says that there's not need for the char variable. printf("%c", int_variable)..will always produce an output which is the ASCII equivalent of the then value of that int_variable. 

So, introducing a new char variable would be absolutely unnecessary.

Always keep in mind..the programs that we make always have to be compact. The most compact and the most efficient program bags the prize

You could simplify and use a for loop instead.

  1. #include
  2.  
  3. int main(void)
  4. {
  5.  
  6. printf("Printing ASCII values Table...\n\n");
  7.  
  8. for (int i = 1; i <= 255; ++i)
  9. {
  10. printf("\nValue:%d = ASCII Character:%c", i, i); /*This change has been made as per the comment. Thank you anonymous Blog Viewer ... */
  11. }
  12. printf("\n\nEND\n");
  13.  
  14. return 0;
  15. }

We should define (char)c=num(int); such as in this code.


  1. #include
  2. #include
  3. main()
  4. {
  5. int num;
  6. char c;
  7.  
  8. printf("Printing ASCII values Table...\n\n");
  9.  
  10. num = 1;
  11.  
  12. while(num<=255)
  13.  
  14. {
  15. c=num;
  16. printf("\nValue:%d = ASCII Character:%c", num, c);
  17. num++;
  18. }
  19.  
  20. printf("\n\nEND\n");
  21. getche();
  22.  
  23. }


C Program to Printing ASCII Table with Numbers and corresponding characters



  1. #include
  2. void main()
  3. {
  4. int i;
  5. char j;
  6. for (i=0,j=0;i<=255;j++,i++)
  7. {
  8. printf("character %c ,Value %d\n", j,i);
  9. }
  10. }