Documentos de Académico
Documentos de Profesional
Documentos de Cultura
K. M. Nasim (Rusho)
Roll:081014
Course No: EEE-152
Course name: Fundamentals of computing Sessional
GMail Address: rusho.eee.08@gmail.com
EEE-152__Programs & Their Outputs -2-
Chapter-1 (Overview of C)
Program:
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{ Output: 40
clrscr();
int a,b,c;
a=13;
b=27;
c=a+b;
printf("%d",c);
getch();
}
Program:
#include <stdio.h>
#include <math.h>
#include <conio.h> Output:
void main() Enter the value of angle
{ 45
clrscr(); Result=0.707106
float a,b,c;
printf("Enter the value of angle\n");
scanf("%f",&a);
b=3.1416*a/180;
c=cos(b);
printf("Result=%f",c);
getch();
}
Program:
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
clrscr();
float a,b,c;
scanf("%f %f %f",&a,&b,&c);
printf("a+b+c=%.2f a-b+c=%.2f a*b*c=%.2f a*b/c=%.2f",a+b+c,a-b+c,a*b*c,a*b/c);
getch();
}
Output:
5
10
15
a+b+c=30.00a-b+c=10.00 a*b*c=750.00 a*b/c=3.33
Program:
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
clrscr();
float sum,i; Output:
sum=0;
i=1; 1275
while(i<=50)
{
sum=sum+i;
i=i+1;
}
printf("%.2f",sum);
getch();
}
Program:
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{ Output:
clrscr(); 25
float a,b,c,d; 13
scanf("%f %f %f",&a,&b,&c); 21
d=(a+b+c)/3; Average=19.666666
printf("Average=%f",d);
getch();
}
3. Write a program to read the price of an item an decimal form (Like 15.95) and print
the output in paise (like 1595 paise)
Program:
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{ Output:
clrscr(); 11
float taka; paisa=1100
int paisa;
scanf("%f",&taka);
paisa=taka*100;
printf("paisa=%d",paisa);
getch();
}
1. Write a program to count the number of boys whose weight is less than 50kgs and
height is greater than 170 cm.
Program:
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main ()
{
clrscr();
int count,i;
float weight,height;
count=0;
printf("Enter weight and height of 5 boys\n");
for (i=1; i<=5; i++)
{
scanf("%f%f",&weight,&height);
if(weight<50 && height>170)
count=count+1;
}
printf("Number of boys of weight <50kgs and height >170 cm=%d\n",count);
getch();
}
Output:
Enter weight and height of 5 boys
45
172
49
178
56
179
58
180
56
145
Number of boys of weight <50kgs and height >170 cm=2
Program:
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define ACCURACY 0.001
void main ()
{clrscr(); Output:
int n,count; Enter the value of x
float x,term,sum; 3
printf("Enter the value of x\n"); Terms=14 Sum=20.085470
scanf("%f",&x);
n=term=sum=count=1;
while(n<=100)
{term=term*x/n;
sum=sum+term;
count=count+1;
if(term<ACCURACY)
n=999;
else
n=n+1;}
printf("Terms=%d Sum=%f\n",count,sum);
getch();}
Program:
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
clrscr();
int a,b,c;
printf("Input the three numbers respectively\n");
scanf("%d%d%d",&a,&b,&c);
if(a>b && a>c) Output:
printf("The Largest number is %d",a); Input the three numbers respectively
else if(b>a && b>c) 5
printf("The Largest number is %d",b); 9
else 4
printf("The Largest number is %d",c); The Largest number is 9
getch();
}
6. Write a program to convert a CGPA to its equivalent results according to the following conditions:
If CGPA 3.75 then write ‘Honours’
3.00<CGPA<3.75, then write ‘First class’
2.00<CGPA<2.99, then write ‘Second class’
CGPA<1.99, then write ‘Fail’
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float CGPA;
printf("Enter your CGPA:"); Output:
scanf("%f",&CGPA); Enter your CGPA:2.99
if (CGPA>=3.75) your grade is Second class
printf("your grade is Honours");
else if (3.75>CGPA&&CGPA>=3)
printf("your grade is first class");
else if (3>CGPA&&CGPA>=1.99)
printf("your grade is Second class");
else
printf("your grade is fail");
getch();
}
7. Write a program to determine whether a number is ‘odd’ or ‘even’ and print the message
NUMBER IS ODD
OR
NUMBER IS EVEN
(a) Without using else option (b) with else option
(a)
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
clrscr(); Output:
int i, a; Enter your number:7
printf("Enter your number:"); your number is odd
scanf("%d",&a);
if(a%2==0)
printf("your number is even");
if(a%2==1)
printf("your number is odd");
getch();}
8. Write a program to find the number of and the sum of all integers greater than 100 and less than 200
that are divisible by 7.
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
clrscr();
int i,sum=0,count=0;
for (i=101;(i>100&&i<200);i++)
{
if(i%7==0)
{
sum=sum+i;
count++;
}
}
printf("count=%d sum=%d",count,sum);
getch();
}
Output:
105 112 119 126 133 140 147 154 161 168 175 182 189 196
count=14 sum=2107
3. Write a program to print the “Power of 2” for the power 0 to 20, both positive and negative.
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
clrscr();
long int p=1;
int n;
double q;
printf("\n 2 to the power n n 2 to the power -n\n");
for (n=0;n<=20;n++)
{ if(n==0)
p=1;
else
p=p*2;
q=1/(double)p;
printf("\n%10ld%15d%20.12lf\n",p,n,q);}
getch();
}
6. Write a program using while loop to reverse the digits of the number. For example, the number
12345 should be written as 54321
Program:
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int n,s=0;
long int a,b;
printf("\nEnter a number of 5 digits=");
scanf("%ld",&a);
printf("\n The reverse digits are =");
for(n=1;n<=5;n++)
{
b=a%10;
printf("%ld",b);
a=a/10;
} Output:
getch(); Enter a number of 5 digits=46524
} The reverse digits are=42564
Prograns:
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int n,s=0;
long int a,b;
printf("\nEnter a number of 5 digits=");
scanf("%ld",&a);
for(n=1;n<=5;n++)
{
b=a%10;
a=a/10;
s=s+b;
}
printf("\n sum of this 5 digits is =%d",s); Output:
getch(); Enter a number of 5 digits=13245
} sum of this 5 digits is =15
9. Write a program that will read a positive integer and print its binary equivalent.
(Hints: The bit of the binary representation of an integer can be generated by repeatedly dividing
the number and the successive quotients by 2 and saving the remainder, which is either 0 or 1, after
each division.)
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{clrscr();
long int a,e=0,b=0,c=1,d ;
printf("Enter Your Decimal number:");
scanf("%ld",&a);
while(a>0)
{c=a%2; printf("%ld",e);
d=c*pow(10,b); //printf("\n%ld",e);
//printf("%3ld",d); getch();}
a=a/2; Output:
e=e+d; Enter Your Decimal number:6
b++;} 110
10. Write a program to read the age of 100 (Here 5) persons and count the number of
persons in the age group 50 to 60. Use for and continue statement.
Program:
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a,c=0,n;
printf("Enter the age:");
for(a=1;a<=5;a++)
{
scanf("%d",&n);
if(n>=50&&n<=60) Output:
c++; Enter the age=45
continue; 55
} 56
printf("The no of persons in the age 45
50 to 60 is %d",c); 78
getch(); The no of persons in the age 50 to 60
} is=2
Chapter-7 (Array)
1. Write a program to find the sum of 10 real numbers by using one dimensional array.
Program:
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int num[5],i,sum=0;
for(i=0;i<5;i++)
{ Output:
printf("\nEnter num[%d]: ",i+1); Enter num[1]:5
scanf("%d",&num[i]); Enter num[2]:8
sum=sum+num[i];} Enter num[3]:7
printf("sum=%d",sum); Enter num[4]:9
getch(); Enter num[5]:3
} Sum=32
Chapter-11 (Pointer)
1. A file named DATA contains a series of integer numbers. Code a program to read these numbers and
then write all odd numbers to a file called ODD and all even numbers to a file to be called EVEN.
Home assignment-01
Decision making and looping
Q.1. Write programs to print the following output using while loops.
(a)
Program:
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a=1,b,c,n;
printf("Enter the value of n:");
scanf("%d",&n);
while(a<=n)
(b)
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int i,j,n,c;
printf("Enter the value of n:");
scanf("%d",&n);
c=1;
i=1;
while(i<=n)
{j=5; Output:
while(j>=i) Enter the value of n:5
{printf("%d",c); 11111
j--;} 1111
i++; 111
printf("\n");} 11
getch();} 1
(c)
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int i,j,n;
printf("Enter the value of n:");
(d)
Program:
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a=1,b,c,n;
printf("Enter the value of n:");
scanf("%d",&n);
while(a<=n)
{b=n;
while(b>=a){
printf(" ");
b--;}
c=1; Output;
while(c<=a) Enter the value of n:5
{printf("%2d",a); 1
c++;} 22
printf("\n\n"); 333
a++;} 4444
getch();} 55555
(e)
Program:
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a=1,b,c,n;
printf("Enter the value of n:");
scanf("%d",&n);
while(a<=n)
Q.2. Write programs to print the following output using for loops.
(a)
Program:
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a,b,c,n;
printf("Enter the value of n:"); Output:
scanf("%d",&n); Enter the value of n:5
for(a=1;a<=n;a++) 1
{for(b=1;b<=a;b++) 11
printf("1"); 111
printf("\n");} 1111
getch();} 11111
(b)
(d)
Program:
#include<stdio.h>
#include<conio.h>
main()
{clrscr();
int a,b,c,n;
printf("Enter the value of n:");
scanf("%d",&n);
for(a=1;a<=n;a++)
{//for(b=n;b>=a;b--) Output;
//printf(" "); Enter the value of n:5
for(c=1;c<=a;c++) 1
printf("%2d",a); 22
printf("\n\n");} 333
getch();} 4444
55555
(e)
Program:
(b)
Program:
(d)
Program:
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a=1,b,c,n;
printf("Enter the value of n:");
scanf("%d",&n);
do
{
b=n;
do
(e)
Program:
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a=1,b,c,n;
printf("Enter the value of n:");
scanf("%d",&n);
do
{
b=n;
do
{
printf(" ");
b--;
}
while(b>=a);
c=1;
do
{
printf("%2d",a);
c++;
}
while(c<=a); printf("\n\n");
(a) (b)
1 1111111111
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1111111111
1111111
(a)
Program:
#include<stdio.h>
#include<conio.h>
main()
{clrscr();
int a,b,c,n;
printf("Enter the value of n:");
scanf("%d",&n);
for(a=1;a<=1;a++)
{printf("1");}
printf("\n");
for(a=1;a<=n-3;a++) Output;
{printf("1"); Enter the value of n:7
for(b=1;b<=a;b++) 1
{printf(" ");} 1 1
printf("1\n");} 1 1
for(a=1;a<=n;a++) 1 1
{printf("1");} 1 1
getch();} 1111111
(b)
Program:
#include<stdio.h>
#include<conio.h>
(a) 1 (b) 1
232 1 1
34543 1 1 1
4567654 1 1 1 1
567898765 1 1 1 1 1
1 1 1 1 1 1
(a)
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int i,j,c,n;
printf("Enter n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
putchar(' ');
}
c=i;
for(j=1;j<=2*i-1;j++)
{
printf("%d",c);
(b)
Program:
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a,b,c,n;
printf("Enter the value of n:");
scanf("%d",&n);
for(a=1;a<=n;a++)
{
for(b=1;b<=n-a;b++)
{
putchar(' ');
}
for(b=1;b<=2*a-1;b++)
{
if(b==1)
printf("1");
else if(b==2*a-1)
printf("1");
else if(a==n-1)
printf("1"); printf("1");
else }
Q.6. Write programs to print the uppercase letters (i.e. A to Z) so that the output look like
(a)
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int n,i,j;
printf("Enter n :");
scanf("%d",&n);
printf("\n");
for (i=1;i<=n;i++)
{for(j=1;j<=n-i;j++)
{putchar(' ');}
(b)
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
int i,j,n;
printf("Enter n: ");
scanf("%d",&n);
for(i=1;i<=n;i++) Output;
{for(j=1;j<=12;j++) Enter n: 7
{if((i==1||j==1||i==n||j==12||j==12-i+1) 111111111111111
&&(i==1||i==n||j==12-i+1)) 1
{printf("1");} 1
else 1
{putchar(' ');}} 1
printf("\n");} 1
getch();} 111111111111111
(c)
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
int n,i,j;
printf("Enter n: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
(d)
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int n,i,j;
printf("Enter n: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{for(j=1;j<=8;j++)
{ Output;
if((j==1||i==n||j==8||i==1||i==4) Enter n: 7
&&(j==1||i==1||i==n||i==4)) 11111111
{printf("1");} 1
else 1
{putchar(' ');} 11111111
} 1
printf("\n");} 1
getch();} 11111111