0% found this document useful (0 votes)
8 views

3

The document outlines various programming problems and their solutions using C language, including temperature conversion, area and perimeter calculations for geometric shapes, and number manipulations. Each problem is accompanied by flowcharts, algorithms, and sample C code with outputs. The document serves as a practical guide for students in the Artificial Intelligence and Data Science branch, focusing on problem-solving through programming.

Uploaded by

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

3

The document outlines various programming problems and their solutions using C language, including temperature conversion, area and perimeter calculations for geometric shapes, and number manipulations. Each problem is accompanied by flowcharts, algorithms, and sample C code with outputs. The document serves as a practical guide for students in the Artificial Intelligence and Data Science branch, focusing on problem-solving through programming.

Uploaded by

cysvnrvjiet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 31

DEPARTMENT OF CSE-(CYS,DS) AND AI&DS

BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

2.Problem statement: Write a C program to convert temperature from Fahrenheit to


Celsius and vice versa (c=(fh-32)/1.8 and f=(c*1.8)+32.

Flowchart

Algorithm
step 1: start
step 2: declare f,c
step 3:input f
step 4: c=(f-32)*5/9
step 5: print c
step 6: end
C program

Programming for problem solving Lab 24071A7256 page. 67


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

Flowchart

Algorithm
Step 1:start
Step 2:declare real c,f
Step 3:input c
Step 4:f=(c*1.8)+32
Step 5: print f
Step 6:end

Programming for problem solving Lab 24071A7256 page. 68


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

C program
#include<stdio.h>
int main()
{
float c,f;
printf("enter the value of c");
scanf("%f",&c);
f=(c*1.8)+32;
printf("%f",f);
}

Output
enter the value of c
37
98.599998
Process returned 0 (0x0) execution time : 5.148 s
Press any key to continue.

Programming for problem solving Lab 24071A7256 page. 69


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

3.Problem statement: Write a C program to find area and perimeter of a circle.


(area=∏r2 perimeter=2∏r).
Area of circle
Flowchart

Algorithm
Step 1:start
Step2:declare integer a,r
Step 3:input r
Step 4:assign a=3.14*r*r
Step 5:print a
Step 6:end

C program
#include<stdio.h>
int main(){
int r,a;
printf("enter the value of r");

Programming for problem solving Lab 24071A7256 page. 70


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

scanf("%d",&r);
a=3.14*r*r;
printf("%d",a);
}

Output
enter the value of r
45
6358
Process returned 0 (0x0) execution time : 11.053 s
Press any key to continue.

Perimeter of circle
Flowchart

Programming for problem solving Lab 24071A7256 page. 71


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

Algorithm
Step 1: start
Step 2:declare integer r,p
Step 3:input r
Step 4:assign p=2*(3.14)*r
Step 5:print p
Step 6: end

C program
#include<stdio.h>
int main(){
int r,p;
printf("enter the value of r");
scanf("%d",&r);
p=2*(3.14)*r;
printf("%d",p);
}

Output
enter the value of r
21
131
Process returned 0 (0x0) execution time : 2.742 s
Press any key to continue.

Programming for problem solving Lab 24071A7256 page. 72


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

4.Problem statement: What is least number must be added to x to obtain a number


exactly divisible by y.(find rem=x%y Subtract remainder from y, the answer will be
least number must be added)
Flowchart

Algorithm
Step 1:start
Step 2:declare integer x,y,n
Step 3:input x
Step 4:input y
Step 5: assign n=y-(x%y)
Step 7: print n
Step 8:end

Programming for problem solving Lab 24071A7256 page. 73


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

C program
#include<stdio.h>
void main()
{
int x,y,n;
printf("enter the values of x,y");
scanf("%d%d",&x,&y);
n=y-(x%y);
printf("%d",n);
}

Output
enter the values of x,y
23
7
5
Process returned 1 (0x1) execution time : 3.797 s
Press any key to continue.

Programming for problem solving Lab 24071A7256 page. 74


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

5.Problem statement: What is the least number must be subtracted from x to get the
number exactly divisible by y. (Find remainder x%y and remainder is the least number
must be subtracted)
Flowchart

Algorithm
Step 1:start
Step 2:declare integer x,y,r
Step 3:input x
Step 4:input y
Step 5:assign r=x%y
Step 6:print r
Step 7:end

Programming for problem solving Lab 24071A7256 page. 75


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

C program
#include<stdio.h>
int main()
{
int x,y,r;
printf("enter the values of x,y");
scanf("%d%d",&x,&y);
r=x%y;
printf("%d",r);
}

Output
enter the values of x,y
22
7
1
Process returned 0 (0x0) execution time : 3.233 s
Press any key to continue.

Programming for problem solving Lab 24071A7256 page. 76


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

6.Problem statement: Write a C program to calculate area and perimeter of a right angled
triangle. (Area=1/2*b*h perimeter=w+h+sqrt(w*w+h*h)

Flowchart

Algorithm
Step 1:start
Step 2:declare real a,p,b,h,w
Step 3:input b
Step 4:input h
Step 5:input w

Programming for problem solving Lab 24071A7256 page. 77


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

Step 6:assign a=(0.5)*b*h


Step 7:assign p=w+h+sqrt((w*w)+(h*h))
Step 8:print a
Step 9:print p
Step 10:end

C program
#include<stdio.h>
int main()
{
float a,p,b,h,w;
printf("enter the values of b,h,w");
scanf("%f%f%f",&b,&h,&w);
a=(0.5)*b*h;
p=w+h+sqrt((w*w)+(h*h));
printf("%f,%f",a,p);
}

Output
enter the values of b,h,w
4
4
3
8.000000,12.000000
Process returned 0 (0x0) execution time : 5.105 s
Press any key to continue.

Programming for problem solving Lab 24071A7256 page. 78


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

7.Problem statement: On dividing x by a certain number, the quotient is y and the


remainder is z. Write a C program to find the number. (Number=x-z/y)

Flowchart

Algorithm
Step 1:start
Step 2:declare integer x,y,z,n
Step 3:input x
Step 4:input y
Step 5:input z
Step 6:assign n=(x-z)/y

Programming for problem solving Lab 24071A7256 page. 79


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

Step 7:print n
Step 8:end

C program
#include<stdio.h>
int main()
{
int x,y,z,n;
printf("enter the values of x,y,z");
scanf("%d%d%d",&x,&y,&z);
n=(x-z)/y;
printf("%d",n);
}

Output
enter the values of x,y,z
32
7
4
4
Process returned 0 (0x0) execution time : 8.827 s
Press any key to continue.

Programming for problem solving Lab 24071A7256 page. 80


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

11.Problem statement: Write a C program to convert centimeters to meters and meters


to kilometers. (1 meter=100 centimeters 1 kilometer=1000 meters)

Convertion of cm to m
Flowchart
Algorithm
Step 1:start
Step 2:declare real c,m
Step 3:input c
Step 4:assign m=c/100
Step 5:print m
Step 6:end

C program
#include<stdio.h>
int main()
{
float c,m;
printf("enter the value of c");
scanf("%f",&c);
m=c/100;
printf("%f",m);

Programming for problem solving Lab 24071A7256 page. 81


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

Output
enter the value of c
50
0.500000
Process returned 0 (0x0) execution time : 9.054 s
Press any key to continue.

Convertion of m to km
Flowchart

Algorithm
step 1:start
step 2:declare real k,m
step 3:input m

Programming for problem solving Lab 24071A7256 page. 82


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

step 4:assign k=m/1000


step 5:print k
step 6:end

C program
#include<stdio.h>
int main()
{
float k,m;
printf("enter the value of m");
scanf("%f",&m);
k=m/1000;
printf("%f",k);
}

Output
enter the value of m
30
0.030000
Process returned 0 (0x0) execution time : 3.351 s
Press any key to continue.

Programming for problem solving Lab 24071A7256 page. 83


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

12.Problem statement: Write a C program to convert the given numbers of days into
years, months and days. (Years = days/365; //Ignoring leap year ;Weeks = (days
%365)/7 ;Days = days- ((years*365) + (weeks*7)).
Flowchart

Algorithm
Step 1:start
Step 2:declare integer nd,y,w,D

Programming for problem solving Lab 24071A7256 page. 84


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

Step 3:input nd

Step 4:assign y=nd/365


Step 5:assign w=(d%365)/7
Step 6:assign D=nd-((y*365)+(w*7))
Step 7:print y
Step 8:print w
Step 9:print D
Step 10:end

C program
#include<stdio.h>
int main()
{
int nd,y,w,D;
printf("enter the value of n,d");
scanf("%d",&nd);
y=nd/365;
w=(nd%365)/7;
D=nd-((y*365)+(w*7));
printf("%d,%d,%d",y,w,D);
}

Output
enter the value of n,d
13,29
3,33,3
Process returned 0 (0x0) execution time : 7.993 s

Programming for problem solving Lab 24071A7256 page. 85


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

Press any key to continue.


13.Problem statement: Write a C program to calculate the angle of a rectangle if two
angle are given as input. (a+b+c=180)

Flowchart

Algorithm
Step 1:start
Step 2:declare integer a,b,c
Step 3:input a
Step 4:input b
Step 5:assign c=180-(a+b)
Step 6:print c
Step 7:end

Programming for problem solving Lab 24071A7256 page. 86


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

C program
#include<stdio.h>
int main()
{
int a,b,c;
printf("enter the values of a,b");
scanf("%d%d",&a,&b);
c=180-(a+b);
printf("%d",c);
}

Output
enter the values of a,b
70
60
50
Process returned 0 (0x0) execution time : 6.184 s
Press any key to continue.

Programming for problem solving Lab 24071A7256 page. 87


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

15.Problem statement: Write a C program to find addition of two numbers using


subtraction operator. Sum=a-(-b).

Flowchart

Algorithm
Step 1:start
Step 2:declare integer a,b,c
Step 3:input a
Step 4:input b
Step 5:assign c=a-(-b)
Step 6:print c
Step 7:end

Programming for problem solving Lab 24071A7256 page. 88


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

C program
#include<stdio.h>
int main()
{
int a,b,c;
printf("enter the values of a,b");
scanf("%d%d",&a,&b);
c=a-(-b);
printf("%d",c);
}

Output
enter the values of a,b
6
42
48
Process returned 0 (0x0) execution time : 5.076 s
Press any key to continue.

Programming for problem solving Lab 24071A7256 page. 89


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

16.Problem statement: Write a C program to read a character, and two integer


numbers and print the ASCII value of the given character

Algorithm
Step 1:start
Step 2:declare character c
Step 3:read c
Step 4:print ASCII of c
Step 5:end

C program

Programming for problem solving Lab 24071A7256 page. 90


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

17.Problem statement: Write a C Program to calculate area and perimeter of a triangle.


Perimeter=(a+b+c) ;s=(a+b+c)/2;Area=sqrt(s*(s-a)(s-b)*(s-c))

Flowchart

Programming for problem solving Lab 24071A7256 page. 91


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

Algorithm
Step 1:start
Step 2:declare integer a,b,c,p,s,ar
Step 3:input a
Step 4:input b
Step 5:input c
Step 6:assign p=a+b+c
Step 7:assign s=(a+b+c)/2
Step 8:assign ar=sqrt(s*(s-a)*(s-b)*(s-c))
Step 9:print p
Step 10:print ar
Step 11:end

C program
#include<stdio.h>
int main()
{
int a,b,c,p,s,ar;
printf("enter the values of a,b,c");
scanf("%d%d%d",&a,&b,&c);
p=a+b+c;
s=(a+b+c)/2;
ar=sqrt(s*(s-a)*(s-b)*(s-c));
printf("%d,%d",p,ar);
}

Programming for problem solving Lab 24071A7256 page. 92


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

Output
enter the values of a,b,c
3
4
5
12,6
Process returned 0 (0x0) execution time : 3.770 s
Press any key to continue.

Programming for problem solving Lab 24071A7256 page. 93


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

19.Problem statement: Write a C Write a program to read the values of x, y and z and
print the results of the following expressions in one line. 1.(x+y+z) / (x-y-z) 2.
(x+y+z) / 3 3.(x+y) * (x-y) * (y-z)
Flowchart

Algorithm
Step 1:start
Step 2: declare integer x,y,z,r,a,m
step 3:input x
step 4:input y
step 5:input z
step 6:assign r=(x+y+z)/(x-y-z)
step 7:assign a=(x+y+z)/3

Programming for problem solving Lab 24071A7256 page. 94


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

step 8: assign m=((x+y)*(x-y)*(y-z)


step 9:print r
step 10: print a
step 11:print m
step 12:end

C program
#include<stdio.h>
int main()
{
int x,y,z,r,a,m;
printf("enter the values of x,y,z");
scanf("%d%d%d",&x,&y,&z);
r=(x+y+z)/(x-y-z);
a=(x+y+z)/3;
m=((x+y)*(x-y)*(y-z));
printf("%d,%d,%d",r,a,m);
}

Output
enter the values of x,y,z
8
3
1
3,4,110
Process returned 0 (0x0) execution time : 2.333 s
Press any key to continue.

Programming for problem solving Lab 24071A7256 page. 95


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

20.Problem statement: Write a C program to Calculate Compound interest


(CI=p(1+r/100)n

Flowchart

Algorithm
Step 1:start
Step 2:declare real c,p,r,n
Step 3:input p
Step 4:input r
Step 5:input n
Step 6:assign c=p*((1+(r/100))^n)

Programming for problem solving Lab 24071A7256 page. 96


DEPARTMENT OF CSE-(CYS,DS) AND AI&DS
BRANCH: ARTIFICIAL INTELLEGENCE AND DATA SCIENCE

Week no. :3 Date:30-9-2024

Start 7:print c
Step 8:end

C program
#include<stdio.h>
int main()
{
float c,p,n,r;
printf("enter the values of p,r,n");
scanf("%f%f%f",&p,&r,&n);
c=p*(pow((1+(r/100)),n));
printf("%f",c);
}

Output
enter the values of p,r,n
1200
5.4
2
1333.099243
Process returned 0 (0x0) execution time : 12.277 s
Press any key to continue.

Programming for problem solving Lab 24071A7256 page. 97

You might also like