Search This Blog

Thursday, 21 May 2020

programming C ( 2020/05/21 LAB session codes)

2020.05.21 lab session

1).   #include <stdio.h>
       #include <stdlib.h>

       int main()


{
      int x=0;

      while(x<=100)
 {
      printf("%d ",x);
      x++;
 }
return 0;
}


2).      #include <stdio.h>
          #include <stdlib.h>

          int main()


{
          int x=0;

          while(x<=100)
 {
        printf("%d ",x);
        printf("\n");
        x++;
 }

int y=0 ,sum;
do {
        printf("%d ",y);
        y++;
   }
while (y<=100);
return 0;
}

 
Add caption
    
3).     #include <stdio.h>
        #include <stdlib.h>

        int main()


{
      int count,marks=0,total=0;
      float average=0;

      while(count<10){

      printf("Enter the marks for the subject \n");
      scanf("%d",&marks);
     total=marks+total;
     count++;

}

     average=total/10;
     printf("the average is :%f",average);
     printf("the total is  \n",&total);

     if(average<50)
  {
      printf("fail");

  }
  else

  {
      printf("pass");
  }

}


 


   

4).    #include <stdio.h>
       #include <stdlib.h>

       int main()


{
     nt num, i=1, factorial;
     factorial=1;

    printf("enter the  number to find the factorial:");
    scanf("%d",&num);

    while(i<=num)
   {
         factorial*=i;
         i++;

   }
     printf("the factorial of %d is : %d",num,factorial);

     return 0;
}

    

5).    #include <stdio.h>


        #include <stdlib.h>

        int main()


{
       int num, sum=0;
       printf("enter the number: \n");
       scanf("%d",&num);

       while(num !=0)
   {
       sum=sum + num%10;
       num=num/10;
   }
      printf("%d",sum);

      return 0;
}

  

Monday, 18 May 2020

programming C(repetition)

  flow chart to display the following number series(while)


#include <stdio.h>


int main()
{
  int counter=1;

  while(counter<=100)

  {
      printf("%d",counter);
      counter++;
  }
}
    
   
                                                                                                                                



fun code (this is error not correct code only for funny)      
                                                                                                                   
while("counter<=100 \n")
add this one for "while" part







programming C( selection)

  input admission number,a module mark and display admission number with grade(if ,else if content)

marks      grade

>=75         A
65-75        B
55-65        C
<55           F

ex:

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

int main()
{
  int admno,marks;
  char grade;
  printf("enter admission number");
  scanf("%d",&admno);
  printf("enter module mark");
  scanf("%d",&marks);
  if (marks>=75)
  grade='A';
  else if (marks>=65)
  grade='B';
  else if (marks>=55)
  grade='C';
  else
  grade='F';
  printf("admission number %d grade is %c \n ",admno,grade);
}

   



programming C(switch structure)

   in put a character and display the vowel or not
(switch content)

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

int main()
{
   char ch;
   printf("enter a character");
   scanf("%c",&ch);

   switch(ch)
   {
       case 'a':printf("a is a vowel");break;
       case 'e':printf("e is a vowel");break;
       case 'i':printf("i is a vowel");break;
       case 'o':printf("o is a vowel");break;
       case 'u':printf("u is a vowel");break;
       default:printf("%c is not a   vowel",ch);
   }
}

     


programming C( switch structure)

   even number and odd number(if and switch content)

if content


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

int main()
{
    int no,ans;
    printf("enter a number");
    scanf("%d",&no);

    ans=no%2;

    if(ans==0)
    printf("%d is an even number",no);

    else
    printf("%d is an odd number",no);

    return 0;
}

write the above programe using switch

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

int main()
{
   int no,ans;
   printf("enter a number");
   scanf("%d",&no);

   ans=no%2;

   switch(ans)
   {
       case 0:printf("%d is an even",no);break;
       case 1:printf("%d is an odd",no);break;
   }

}

 

    

programming C( switch structure)

  enter month number and display the name of the month(switch content)


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

int main()
{
    int opt;
    printf("enter month number");
    scanf("%d",&opt);

    switch(opt){

    case 1:printf("january");break;
    case 2:printf("february");break;
    case 3:printf("march");break;
    case 4:printf("april");break;
    case 5:printf("may");break;
    case 6:printf("june");break;
    case 7:printf("july");break;
    case 8:printf("august");break;
    case 9:printf("september");break;
    case 10:printf("october");break;
    case 11:printf("november");break;
    case 12:printf("december");break;


    default :printf("invalid month number");
    }

  

Sunday, 17 May 2020

programming C(small value and largest value)

    largest value and smallest value among the three numbers(if and switch content)

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

int main()
{
    int no1,no2,no3;
    printf("Enter three numbers\n");
    scanf("%d %d %d",&no1,&no2,&no3);

    if(no1<no2 && no1<no3)
    {
            printf("%d is the smallest number\n",no1);
    }
    else if(no2<no3)
    {
        printf("%d is the smallest number\n",no2);
    }
    else
    {
        printf("%d is the smallest number\n",no3);
    }

    if(no1>no2 && no1>no3)
    {
    printf("%d is the largest number",no1);
    }
    else if(no2>no3)
    {
    printf("%d is the largest number",no2);
    }
    else
    {
    printf("%d is the largest number",no3);
    }
    return 0;
}

    

programming C(high number)

  Write a program to input two numbers and display the highest number (if content)


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

    int main()
    {

      int no1,no2,max;
      printf("enter two numbers \n");
      scanf("%d %d",&no1,&no2);
      max=no1;
      if(no2>max)
      max=no2;

      printf("the highest is %d\n",max);

     }

     

Saturday, 16 May 2020

programming C(avarage)

two decimal numbers avarage


#include<stdio.h>
int main()
{
    float x,y,z;
    printf("enter the first decimal:\n");
    scanf("%f", &x);
    printf("enter the second decimal:\n");
    scanf("%f", &y);
    z=(x+y)/2;
    printf("avarage is: %.2f", z);
    return 0;
}

   

programming C(add detals and salary)

name,colombo or not,experience year,monthly sale,salesman

#include <stdio.h>



int main()
{



    char Name[10];
    char City;
    int Exp;
    float BaSal,Sales,Add1,Add2,MonRe;



    printf("Enter Your Name : ");
    scanf("%s",&Name);



    printf("Colombo or not (y/n) : ");
    scanf("%s",&City);



    printf("Enter Experience (Number of Years) : ");
    scanf("%d",&Exp);



    printf("Enter Your Basic Salary : ");
    scanf("%f",&BaSal);



    printf("Enter Your Monthly Sales : ");
    scanf("%f",&Sales);





    Add1 = (BaSal * 0.1);
    Add2 = 2500.0;



    if(City=='y'){



        if(Exp>=5){



        if(Sales<25000.0){
        MonRe=(Sales * 0.1)+BaSal +Add1+2500;
        printf("M remuneration of a salesman : %.2f",MonRe);
    }



   else if(Sales>=25000 && Sales<50000){
        MonRe=(Sales * 0.12)+BaSal+Add1+2500;
        printf("Monthly remuneration of a salesman : %.2f",MonRe);
    }



    else{
        MonRe=(Sales * 0.15)+BaSal+Add1+2500;
        printf("Monthly remuneration of a salesman : %.2f",MonRe);
    }
    }else{
        if(Sales<25000.0){
        MonRe=(Sales * 0.1)+BaSal+2500;
        printf("Monthly remuneration of a salesman : %.2f",MonRe);
    }



   else if(25000 <= Sales && 50000 > Sales){
        MonRe=(Sales * 0.12)+BaSal+2500;
        printf("Monthly remuneration of a salesman : %.2f",MonRe);
    }



    else{
        MonRe=(Sales * 0.15)+BaSal+2500;
        printf("Monthly remuneration of a salesman : %.2f",MonRe);
    }}




    }else{



        if(Exp>=5){



        if(Sales<25000.0){
        MonRe=(Sales * 0.1)+BaSal +Add1;
        printf("Monthly remuneration of a salesman : %.2f",MonRe);
    }



    else if(Sales>=25000 && Sales<50000){
        MonRe=(Sales * 0.12)+Sales+Add1;
        printf("Monthly remuneration of a salesman : %.2f",MonRe);
    }



    else{
        MonRe=(Sales * 0.15)+BaSal+Add1;
        printf("Monthly remuneration of a salesman : %.2f",MonRe);
    }
    }else{
        if(Sales<25000.0){
        MonRe=(Sales * 0.1)+BaSal;
        printf("Monthly remuneration of a salesman : %.2f",MonRe);
    }



    else if(25000 <= Sales && 50000 > Sales){
        MonRe=(Sales * 0.12)+BaSal;
        printf("Monthly remuneration of a salesman : %.2f",MonRe);
    }



    else{
        MonRe=(Sales * 0.15)+BaSal;
        printf("Monthly remuneration of a salesman : %.2f",MonRe);
    }
    }



    }
}

     

programming C(%d %d %d %d %d\n",'A','B','C','a','b','c','0','1,/)

%d %d %d %d %d\n",'A','B','C','a','b','c','0','1

#include<stdio.h>
int main()
{
    printf("%d %d %d %d %d %d %d %d %d %d %d %d %d\n",'A','B','C','a','b','c','0','1','2','$','*','+','/');

}
  

programme C(devided or not devided)

 first one devided by second or its not devided properly second(if content)

#include<stdio.h>
int main()
{
    int x,y;
    printf("enter no1\t");
    scanf("%d",&x);
    printf("enter no2\t");
    scanf("%d",&y);

    if (y%x==0){
        printf("first one is devided by second");

    }
    else {
        printf("it is not devided properly from second");
    }
}
     


programme C(radius of circle)

 radius,diameter,circumference,area


#include<stdio.h>
int main()
{
    float radius,diameter,circumference,area;

    printf("enter the radius of the circle: ");
    scanf("%f",&radius);

    diameter=2*radius;
    circumference=2*3.14159*radius;
    area=3.14159*radius*radius;
    printf("The diameter of the circle is %.3f\n",diameter);
    printf("The circumference ofthe circle isd %.3f\n",circumference);
    printf("The area of the circle is %.3f ",area);
    return 0;


}
       

programming c(pass or fail)

pass mark and fail mark (after 50 pass)

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

int main()
{
    int mark;
    printf("enter your marks");
    scanf("%d",&mark);

    if (mark>50){
        printf("pass");
    }
    else {
        printf("fail");
    }
    return 0;
}

   

                                                                         

programming C(average)

 two numbers average


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

int main()

{
     int no1,no2;
     printf("Enter first Number: ");
     scanf("%d",&no1);
     printf("Enter second number: ");
     scanf("%d",&no2);
     printf("Sum is %d\n",no1+no2);

     float num1,num2,avg;

     printf("Enter first number: ");
     scanf("%f",&num1);
     printf("Enter second number: ");
     scanf("%f",&num2);

     avg= (float)(num1+num2)/2;

     printf("Average of %f and %f is: %.2f",num1,num2,avg);





    return 0;
}

  

programming C

colour,first numb,second numb,third numb,flot numb,hexadecimal numb,octal numb,unsigned value,perecentage sign


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

main()
{
    printf("The color: %s\n","blue");
    printf("First number: %d\n",12345);
    printf("Second number: %04d\n",25);
    printf("Third number: %i\n", 1234);
    printf("Float number: %3.2f\n", 3.14159);
    printf("Hexadecimal: %x\n", 255);
    printf("Octal: %o\n", 255);
    printf("Unsigned value: %u\n", 150);
    printf("Just print the percentage sign %%\n",10);

}

  

programme C( find celsius)

 Fahrenheit convert to celsius


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

int main()
{
   float Cel,Fah;

   printf("Enter Fahrenheit degree \t");
   scanf("%f",&Fah);

   Cel=(Fah-32)*5/9;

   printf("Temperature in Celsius Degrees %f\t",Cel);

   return 0;
}

   

programming C( name and salary)

   salary(if content)


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

int main()
{
   int basic,new_salary;
   char name[20];

   printf("Please enter your name \n");
   scanf("%s",&name);
   printf("Please enter your basic salary \n");
   scanf("%i",&basic);
   if(basic<5000){
    //5% increment

    new_salary=basic*5/100;
    new_salary=basic + new_salary;

   }
   else if(basic>5000&&basic<10000){
   new_salary=basic*10/100;
   new_salary=basic + new_salary;
   }
   else{
   new_salary=basic*15/100;
   new_salary=basic + new_salary;
   }

   printf("Name :%s\nNew Salary :%i",name,new_salary);
}

      

programme C(adding)

adding two numbers


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

int main()
{
    double num1;
    double num2;
    printf("Enter First number: ");
    scanf("%lf", &num1);
    printf("Enter Second number: ");
    scanf("%lf", &num2);

    printf("Answer: %.3f", num1 + num2);

    return 0;
}

  


programme C(mark and place)

   merit , pass , faill  (if content)

#include <stdio.h>
int main()
{
    int marks;
    printf("Enter module marks ");
    scanf("%d", &marks);
    if(marks>=75)
    printf("Merit");
    else if(marks>=60)
    printf("Distinction");
    else if(marks>=40)
    printf("Pass");
    else
    printf("Fail");
}

 








programme C(high number)

  at three numbers find high one(if content)

#include <stdio.h>
int main()
{
     int no1,no2,no3,max;
     printf("Enter Three Numbers ");
     scanf("%d %d %d", &no1, &no2, &no3);
     max=no1;
     if(no2>max)
     max=no2;

     if(no3>max)
     max=no3;

     printf("The Highest is %d \n",max);
}

    

programme C(speed=distance/time)

     find average speed

#include <iostream>

using namespace std;

int main()
{
    float distance,time,speed;

    printf("enter distance?\t");
    scanf("%f",&distance);
    printf("enter time?\t");
    scanf("%f",&time);

    speed=distance/time;

    printf("speed is %f",speed);

    return 0;
}
     

programming C(format commands)

   format commands with modifier output

#include <iostream>

using namespace std;

int main()
{
    printf("%6d%6d%6d\n",2,4,6);
    printf("%6d%6d%6d\n",3,9,27);
    printf("%6d%6d%6d\n",4,16,64);
    return 0;
}

       

programming C(data input and output)

age,welcome age and lest be friends

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

int main()
{

    int age;
    printf("hi how old are you?");
    scanf("%d",&age);

    printf("\n \n");
    printf("welcome %d\n",age);
    printf("lest be friends");
    return 0;
}
    

Friday, 15 May 2020

programming C(values)

   swap the values and display the output


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

int main()
{
    int X,y,temp;

    printf("Enter number for the first variable\n");
    scanf("%d",&X);

    printf("enter number for the second variable\n");
    scanf("%d",&y);

    temp=X;
    X=y;
    y=temp;

    printf("first variable value %d \n",X);
    printf("second variable value %d \n",y);

    return 0;
}

    

programming C (student name with age)

    name with age

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

int main()
{
    char name[50];
    int b_year,age;

    printf("enter your name\n");
    scanf("%s",&name);

    printf("enter your born year\n");
    scanf("%d",&b_year);

    age=2020-b_year;

    printf("student name is %s \n",name);
    printf("student age is %d \n",age);
    return 0;
}

     

programming C(name and school)

    Name and school


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

int main()
{
    char name[25]="kusal mendis";
    printf("%s\n",name);

    char name2[35]="ncfc college";
    printf("%s\n",name2);
}

programming C(two integers total)

  two integers and display the total


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

int main()
{
    int x,y;

    printf("enter first number \n");
    scanf("%d",&x);

    printf("enter second number \n");
    scanf("%d",&y);

    printf("total is %d \n",x+y);
    return 0;

}

    

programming C(two numbers average)

 Numbers average

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

int main()
{
    float x,y,tot,avg;
    printf("enter first number\n");
    scanf("%f",&x);

    printf("enter second number\n");
    scanf("%f",&y);

    tot=x+y;
    avg=tot/2;

    printf("avarage is %f \n",avg);

    return 0;
}



https://programminglanguagensbm.blogspot.com