Monday, 4 November 2013

Write a programme which takes any 4 numbers from users. The program should display the sum of squares of these numbers.


Learning Objectives: The objective of this exercise is to get you to write, compile and run a number of simple programmes in C.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

int main (){
   
    int n1,n2,n3,n4,sum,sqr_sum;
    n1=n2=n3=sum=0;
    //veriable decliration and initilization
   
    printf("\nPROGRAM TO PRINT SUM OF SQUARES OF FOUR NUMBERS");
    printf("\n===============================================\n\n");
    //headings
   
    printf("\n\tEnter 1st Number\t");
    scanf("%d",&n1);
    printf("\n\tEnter 2nt Number\t");
    scanf("%d",&n2);
    printf("\n\tEnter 3rd Number\t");
    scanf("%d",&n3);
    printf("\n\tEnter 4th Number\t");
    scanf("%d",&n4);
    //taking input
   
    sum=n1+n2+n3+n4;
    sqr_sum=(n1*n1)+(n2*n2)+(n3*n3)+(n4*n4);
    //process
   
    system("cls");
    //clear screen to show output screen
   
    printf("\nPROGRAM TO PRINT SUM AND SQUARE OF FOUR NUMBERS");
    printf("\n===============================================\n\n");
    //headings

    printf("\n\tNumber  \tSquare\n");
    printf("\n\t %d  \t\t %d",n1,n1*n1);
    printf("\n\t %d  \t\t %d",n2,n2*n2);
    printf("\n\t %d  \t\t %d",n3,n3*n3);
    printf("\n\t %d  \t\t %d",n4,n4*n4);
   
    printf("\n\t----  \t\t ----");
    printf("\nSum\t%d  \t\t %d",sum,sqr_sum);
    //output

    getch();
    return 0;
   
}


Write a programme which takes any 3 numbers, from the user. The program should find and display their sum and average.


Learning Objectives: The objective of this exercise is to get you to write, compile and run a 
number of simple programmes in C.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

int main (){
   
    int n1,n2,n3;
    float total,avg;
   
    n1=n2=n3=0;
    total=avg=0;
   
   
    printf("\nPROGRAM TO PRINT SUM AND AVRAGE OF THREE NUMBERS");
    printf("\n================================================\n\n");
   
   
    printf("\n\tEnter 1st Number\t");
    scanf("%d",&n1);
    printf("\n\tEnter 2st Number\t");
    scanf("%d",&n2);
    printf("\n\tEnter 3st Number\t");
    scanf("%d",&n3);
   
    total=n1+n2+n3;
    avg=total/3;
   
    system("cls");
   
    printf("\nPROGRAM TO PRINT SUM AND AVRAGE OF THREE NUMBERS");
    printf("\n================================================\n\n");
   
    printf("\n\t1st Number\t%d",n1);
    printf("\n\n\t2st Number\t%d",n2);
    printf("\n\n\t3st Number\t%d",n3);
   
    printf("\n\n\n\tTotal\t%.2f",total);
    printf("\n\tAvgrage\t%.2f",avg);
   
    getch();
    return 0;
   
   

    }

Write a programme which takes any two numbers from user and then ask for to press + to display sum, to press - to display difference, to press * to display product, to press / to display quotient and to press M to display reminder (%).


Learning Objectives: The objective of this exercise is to get you to write, compile and run a 
number of simple programmes in C.

#include<stdio.h>
#include<conio.h>

int main(){
   
    int a,b;
    char dec;
    a=b=0;
    dec=0;
    /* variable deceleration and initialization */
   
    printf("***Simple Arithmetic Operation Calculator***\n");
    printf("***======================================***\n\n");
    /* headings */
   
    printf("Enter any Number\n");
    scanf("%d",&a);
   
    printf("\nEnter another Number\n");
    scanf("%d",&b);
    /* Numbers input */

   
    printf("\nInstruction:\n");
    printf("============\n");
   
    printf("Press + for Addition\n");
    printf("Press - for Substraction\n");
    printf("Press * for Multiplication\n");
    printf("Press / for Division\n");
    printf("Press M for Reminder\n");
   
    dec=getch();
    /* operation decion by user */
   
    switch(dec){
                case '+':
                         printf("\n\nAnswer %d",a+b);
                         break;    
               
                case '-':
                         printf("\n\nAnswer %d",a-b);
                         break;
                   
                case '*':
                         printf("\n\nAnswer %d",a*b);
                         break;
               
                case '/':
                       
                         if(b==0)
                                 printf("\n\nDividing by zero ERROR!!!");                
                         else
                         printf("\n\nAnswer %d",a/b);
                       
                         break;
                       
                case 'M':
                case 'm':

                         printf("\n\nAnswer %d",a%b);
                         break;            
                       
                default:
                        printf("\n\nInvalid Input..!!!");
               
                }
    /* Switch function contains processing of operations */
   
    getch();

    return 0;
   
   

    }