0% found this document useful (0 votes)
43 views10 pages

Maha Pps Ex2 Now

Uploaded by

dheenamyself
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views10 pages

Maha Pps Ex2 Now

Uploaded by

dheenamyself
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

IT22111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

Ex no:
Date: C Programming using Simple statements and expressions
….
1. Print your name , I am an Engineer. Sample:My name is Sivaji , I am an
Engineer. Get familiar with vi, cc , and ./[Link].
AIM:

To execute a basic C program using vi , cc and ./[Link] commands.

PSEUDOCODE:

CPROGRAM:

#include <stdio.h>
void main()
{
printf(“my name is Kaviyarasan\n”);
printf(“I am an engineer”);
}

SAMPLE OUTPUT:

[eea39@mritlin kavi] $ vi ex2a.c


[eea39@mritlin kavi] $ cc ex2a.c
[eea39@mritlin kavi] $ ./[Link]
my name is Kaviyarasan
I am an engineer

RESULT:
Thus a basic C program using vi, cc and ./[Link] commands have been executed
successfully.

Roll No: 039 Page no:


IT22111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

2. Print your details Name , age , Gender(M/F) , Address , CutOff(inHSC) with one
detail per line and tab between label and value.

AIM:

To execute a basic C program to display the basic details of a student using escape
sequence.

PSEUDOCODE:

CProgram:

#include <stdio.h>
void main ()
{
printf(“Name\t:Kaviyarasan \n”);
printf(“Age\t:18\n”);
printf(“Gender\t:male\n”);
printf(“Address\t: Railway Quaters Arakkonam\n”);
printf(“Cutoff\t:156\n”);

SAMPLE OUTPUT:

[eea39@mritlin kavi] $ vi ex2b.c


[eea39@mritlin kavi] $ cc ex2b.c
[eea39@mritlin kavi] $ ./[Link]
Name : Kaviyarasan
Age : 18
Gender : Female
Address : Railway Quaters Arakkonam
Cutoff : 156

RESULT:

Thus a basic C program to display the basic details of a student using escape sequence
have been executed successfully.

Roll No: 039 Page no:


IT22111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

3. Read your details through keyboard and display them. (Use gets() for string).

AIM:
To execute a C Program to get all details through keyboard and display them.

PSEUDOCODE:

C PROGRAM:

#include <stdio.h>
Void main ()
{
char name [50];
char address [100];
int cutoff;
printf(“enter name :”);
gets(name);
printf(“enter address :”);
gets(address);
printf(“enter cutoff :”);
scanf(“%d”,&cutoff);
puts(name);
puts(address);
printf(“%d”,cutoff);
}

Roll No: 039 Page no:


IT22111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

SAMPLE OUTPUT:

[eea39@mritlin kavi] $ vi ex2c.c


[eea39@mritlin kavi] $ cc ex2c.c
[eea39@mritlin kavi] $ ./[Link]

Name : Kaviyarasan
enter address : Railway Quaters Arakkonam
enter cutoff : 156
Kaviyarasan
Railway Quaters Arakkonam
156

RESULT:
Thus the basic linux commands have been learnt and executed successfully.

Roll No: 039 Page no:


IT22111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

4. Kumar has Rs.x and Sheela has Rs.y . Both exchange their amounts. Simulate this as an
interactive C program.

AIM:
To execute a basic C Program to exchange their amounts between Kumar and Sheela.

PSEUDOCODE:

C PROGRAM:

#include <stdio.h>
void main ()
{
int a,b,temp;
printf(“enter amount kumar has :\n”);
scanf(“%d”,&a);
printf(“enter amount sheela has :\n”);
scanf(“%d”,&b);
temp=a;
a=b;
b=temp;
printf(“enter the amount kumar has now :%d\n”,a);
printf(“enter the amount sheela has now :%d\n”,b);
}

Roll No: 039 Page no:


IT22111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

SAMPLE OUTPUT:

[eea39@mritlin kavi] $ vi ex2d.c


[eea39@mritlin kavi] $ cc ex2d.c
[eea39@mritlin kavi] $ ./[Link]
enter amount kumarhas : 20
enter amount sheelahas : 30
enter amount kumar has now : 20
enter amount sheela has now : 30

RESULT:
Hence the interactive C program has been stimulated.

Roll No: 039 Page no:


IT22111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

5. Calculate the daily wage of a labour taking into account the pay per day , number of
hours worked, TA and DA.

AIM:
To calculate a basic C program to calculate the daily wage of a labour.

PSEUDOCODE:

C PROGRAM:

#include <stdio.h>
void main()
{
int a,b,c,d,wages;
printf("enter payment per hour:\t");
scanf("%d",&a);
printf("enter number of hours of work:\t");
scanf("%d",&b);
printf("enter the TA:\t");
scanf("%d",&c);
printf("enter the DA:\t");
scanf("%d",&d);
wages=(a*b)+c+d;
printf("The daily wages of a labour:%d",wages);
}

Roll No: 039 Page no:


IT22111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

SAMPLE OUTPUT:

[eea39@mritlin kavi] $ vi ex2e.c


[eea39@mritlin kavi] $ cc ex2e.c
[eea39@mritlin kavi] $ ./[Link]
enter payment per hour: 200
enter number of hours of work: 8
enter the TA: 400
enter the DA: 1000
The daily wages of a labour: 3000

RESULT :
Thus a basic C program to display the basic details of a student using escapes Sequence
have been executed successfully.

Roll No: 039 Page no:


IT22111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

6. Box 1 has M apples and Box 2 has N apples. Assuming you do not have any other
space/storage to hold the apples, exchange the apples in Box 1 and Box 2. (Swap without
temp).

AIM :
To execute a basic C Program to exchange the number of apples in Box 1 and in Box 2.

PSEUDOCODE:

C PROGRAM :
#include <stdio.h>
void main()
{
int temp,a,b;
printf("Enter number of apples in box 1:\t");
scanf("%d",&a);
printf("Enter number of apples in box 2:\t");
scanf("%d",&b);
a=a+b;
b=b-a;
Roll No: 039 Page no:
IT22111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

a=a-b;
printf("The number of apples in box 1 and box 2 are %d and %d",a,b);
}

SAMPLE OUTPUT:

[eea39@mritlin kavi] $ vi ex2f.c


[eea39@mritlin kavi] $ cc ex2f.c
[eea39@mritlin kavi] $ ./[Link]
Enter number of apples in box 1: 10
Enter number of apples in box 2: 20
The number of apples in box 1 and box 2 are 20 and 10.

RESULT :
Thus a basic C program to display the basic details of a student using escapes Sequence
have been executed successfully.

Roll No: 039 Page no:

You might also like