Function in C exercises (more)

3. Write C code that will output the multiplication table as show below:


1*1=1                   2*1=2                   3*1=3        ……  9*1=1
1+2=2                  2*2=4                   3*2=6         ……  9*2=18
…….                    …….                   …….          ……  …….
1*9=9                   2*8=18                 3*9=27       ……  9*9=81

Solution:

#include <stdio.h>
#include <stdlib.h>
 
void multable(){
     int i,j;
     for(i=1;i<10;i++){
      for(j=1;j<10;j++)
      printf("%d",j);printf("* %d",i);printf("=%d",j*i);printf("\t");
      printf("\n");}
     }
int main(int argc, char *argv[])
{
  multable();
  system("PAUSE");
  return EXIT_SUCCESS;
}

4. Write a program that will ask the user to input three integer values from the keyboard. Then it will print the smallest and largest of those numbers.

Solution:
#include <stdio.h>
#include <stdlib.h>
int maxval(int a,int b,int c){
     int max=a;
     if(max<b) max=b;
     if(max<c) max=c;

     return max;

     
     }
int minval(int a,int b,int c){
     int min=a;
     if(min>b) min=b;
     if(min>c) min=c;

     return min;

     
     }
int main(int argc, char *argv[])
{
  int a,b,c;
  printf("Enter three integer numbers:");
  scanf("d% %d %d",&a,&b,&c);
  printf("Max=%d",maxval(a,b,c)); printf("\n");
  printf("Min=%d",minval(a,b,c));
  printf("\n");
  system("PAUSE");
  return EXIT_SUCCESS; }

HTML Comment Box is loading comments...



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.