Lab1 -ECX3265



Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
   
    printf("LAB1 SESSIONS \n\n");
   
    int sample;
    int exit=0;
   
    while (sample!=0){
   
    printf("main menu.. \n");
    printf("1: WELCOME MESSAGE \n");
    printf("2: COMPARE TWO NUMBERS \n");
    printf("3: CHECK GRADE IS PASS/FAIL \n");
    printf("4: AVERAGE OF 10 NUMBERS \n");
    printf("5: DISPLAY SOLID SQUIRE OF *S \n");
      
    scanf("%d",&sample);
   
    printf("YOU ARE RUNNING SAMPLE %d \n\n",sample);
   
    switch (sample){
        case 1:
            sample1();
            break;
        case 2:
            sample2();
            break;
        case 3:
            sample3();
            break;  
        case 4:
            sample4();
            break;  
        case 5:
            sample5();
            break;
    }
   
    printf("\n\nDO YOU WANT TO EXIT? (YES=1,NO=0)");
    scanf("%d",&exit);
    if (exit==1)
        return 0;

   
    } //end while
   
      
    return 0;
}

int sample1(){
    printf("Welcome to C!\n");
    return 0;

}



int sample2(){

    int num1,num2;
    printf("enter two intergers and I will tell you \n the relationships they satisfy:");
    scanf("%d%d",&num1,&num2);
    printf("\n\n");  
    printf("TWO NUMBERS ARE: [%d] ,[%d]",num1,num2);
    printf("\n\n");  
   
    if (num1 == num2){
        printf("%d is equel to %d\n",num1,num2);
        printf("\n\n");  
    }
   
      
    if (num1 != num2){
        printf("%d is not equel to %d\n",num1,num2);
        printf("\n\n");
    }
   
    if (num1 < num2){
        printf("%d is less than %d\n",num1,num2);
        printf("\n\n");
    }      
      
    if (num1 > num2){
        printf("%d is grater than %d\n",num1,num2);
        printf("\n\n");
    }      

    if (num1 <= num2){
        printf("%d is less than or equel %d\n",num1,num2);
        printf("\n\n");
    }      
   
    if (num1 >= num2){
        printf("%d is grater than or equel %d\n",num1,num2);
        printf("\n\n");
    }
          
    return 0;

}



int sample3(){
    int grade;
    printf("PLEASE ENTER THE GRADE:");
    scanf("%d",&grade);
   
    if (grade > 70)
        printf("Pass\n");
    else
        printf("Fail\n");
   
    return 0;
}

int sample4(){

    int counter,grade,total,average;
    total=0;
    counter=1;
   
    while (counter<=10){
      
        printf("enter grade:");
        scanf("%d",&grade);
        total=total+grade;
        counter=counter+1;
      
    }
    //end while
   
    average = total /10;
    printf("Class average is %d\n",average);
   
    return 0;

}

int sample5(){

    int x,y;
   
    for(x=1;x<6;x++){
      
        for(y=5;y>0;y--){
             printf("*");
        }
      
    printf("\n");    
    }

    return 0;

}



Download source:
https://drive.google.com/file/d/0B_XbnOd307B_UmFYUFpjLVlwNVE/view?usp=sharing


Lab Sheet:
https://drive.google.com/file/d/0B_XbnOd307B_OWFQaTFYWENKWU0/view?usp=sharing

0 comments:

Post a Comment