Sie sind auf Seite 1von 18

ASSIGNMENT

ON

PROGRAMMING ON C++ LANGUAGE.

DEPARTMENT OF ACCOUNTING & INFORMATION SYSTEMS FACULTY OF BUSINESS STUDIES UNIVERSITY OF DHAKA

Submitted to: Minhaj Ferdous Assistant teacher Department of Accounting and Information Systems.

Submitted by: The Gladiator Serial No 01 02 03 04 05 06 Name Md. Al-amin(Group Leader) Md.Akter Hossain Farhana Yasmin Md. Din Islam Moniruzzaman Md. Kowser Bhuiyan ID No 14032 14021 14024 14031 14035 14083

Date of submission: 23 December, 2010

Table of Contents

Sl. No. Programs


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Program to Find out the temperature in Fahrenheit. Factorial of a Number.

Page No.

Program for standard deviation.


Whether a year is a leap year or not. Whether a Number is Prime or Not. Program to find Fibonacci series.

A program for string copying. Two strings are equal or not. Program for finding the length of a string. Program for string concatanation.
Finding power value.

Conversion of Decimal Number to Binary Number.


Program to find NPV, PV. Whether a particular character exists in a string.

Program to sort some numbers in ascending order.


A program to find whether a number is even or odd.

A program to find bigger number among three numbers.


A program to find the value of a quadratic equation.

1. Program to Find out the temperature in Fahrenheit.

#include<stdio.h> #include<conio.h>

void main() { float f,c; clrscr(); printf("Enter centigrade:"); scanf("%f",c);

f=1.8*c+32;

printf("\nThe Fahrenheit is :%.2f",f); getch(); }

2. Factorial of a Number.

#include<stdio.h> #include<conio.h> void main() {int i,n,fact; clrscr(); printf("Enter a numbet to get factorial:"); scanf("%d",&n); if(n==0) printf("\nThe factorial is 1."); else for(i=1;i<n;i++) fact=fact*i; printf("\nThe factorial is %d,",fact); getch(); }

3. Program for Standard Deviation.

#include<stdio.h> #include<conio.h> #include<math.h> void main() { int i,n; float list[50],sum,avg,d,sd; clrscr(); printf("How Many Numbers"); scanf("%d",&n); sum=0; for(i=0;i<n;i++) { printf("\nEnter Number"); scanf("%f",&list[i]); sum=sum+list[i]; avg=sum/n; for(i=0;i,n;i++) d=list[i]-avg; sum=(sum+(d*d)); }

sd=sqrt(sum/n); printf("\nThe standard Deviation is %f",sd); getch(); }

4. Whether a year is a leap year or not.

#include<stdio.h> #include<conio.h> void main() { int a; clrscr(); printf("Enter data to test"); scanf("%d",&a); if((a%4)==0) printf("\nLeap year"); else printf("\nNot Leap Year"); getch(); }

5.Wheather a Number is Prime or Not.

#include<stdio.h> #include<conio.h> void main() { int i,num,result; clrscr(); printf("Enter number to test"); scanf("%d",&num); result=1; for(i=2;i,num/i;i++) if((num%i)==0)result=0; if(result==1) printf("\nThe Number Is Prime"); else printf("\nThe number is Not Prime"); getch(); }

6. Program to find Fibonacci series.

#include<stdio.h> #include<conio.h> void main() { int i,n,a[50]; clrscr(); printf("How Many Numbers?"); scanf("%d",&n); a[0]=1; a[1]=1; for(i=2;i<n;i++) a[i]=a[i-1]+a[i-2]; printf("The Series is"); for(i=0;i<n;i++) printf("%d",a[i]); getch(); }

7. A program for string copying

#include<stdio.h> #include<conio.h> #include<string.h> void main() { char str1[20],str2[20]; clrscr(); printf("Enter a strig:"); scanf("%s",str1); strcpy(str2,str1); printf("The original string is:%s",str1); printf("\nAnd the copy is:%s",str2); getch(); }

8. Two strings are equal or not

#include<stdio.h> #include<conio.h> #include<string.h> void main() { char x[30],y[30]; int f; clrscr(); printf("Enter a string:"); scanf("%s",x); printf("Enter another string:"); scanf("%s",y); f=strcmp(x,y); if(f!=0) printf("\nTwo strings are not equal."); else printf("\nTwo strings are equal."); getch(); }

9. Program for finding the length of a string

#include<stdio.h> #include<conio.h> #include<string.h> void main() { char str[30]; int l; clrscr(); printf("Enter a strig:"); scanf("%s",str); l=strlen(str); printf("\nThe length of the string is:%d",l); getch(); }

13. Program to find NPV,PV


#include<stdio.h> #include<conio.h> #include<math.h> void main() { int i,n; float a[20],cof,d,in,sum=0,npv; clrscr(); printf("\nEnter the cash outflow"); scanf("%f",cof); printf("Enter the enterest rate"); scanf("%f",&in); printf("\nEnter the number of cash inflow"); scanf("%d",&n); for(i=0;i<n;i++) { printf("\nEnter cash inflow for period %d",i+1); scanf("%f",&a[i]); d=1+in; sum=sum+(a[i]+pow(d,i)); } npv=sum-cof; printf("\nPresent value is %f",sum); printf("\nNet Present Value is %f",npv);

getch(); }

14. Whether a particular character exists in a string.

#include<stdio.h> #include<conio.h> #include<string.h> void main() { char *ch,*find,*str; clrscr(); printf("Enter a string"); scanf("%s",str); printf("Enter a chracter"); scanf("%s",ch); find=strstr(str,ch); if(find) printf("\nThe charater exists in the string"); else printf("\nThe chracter doesnot exist in the string"); getch(); }

15. Program to sort some numbers in ascending order


#include<stdio.h> #include<conio.h> void main() { int i,j,n,list[30],temp; clrscr(); printf("how many numbers"); scanf("%d", &n); for(i=0;i<n;i++) { printf("\nEnter number"); scanf("%d", &list[i]); } for(i=0;i<n-1;i++) { for(j=i+1;j<n-1;j++) { if(list[i]>list[j]) { temp=list[i]; list[i]=list[j]; list[j]=temp; } }

} printf("\n"); for(i=0;i<n;i++) printf("%d",list[i]); getch(); }

16. A program to find whether a number is even or odd.

#include<stdio.h> #include<conio.h> void main() { int num; printf(" Enter a number"); scanf("%d",&num); if((num%2)==0) printf("\n The number is even"); else printf("\n The number is odd"); getch(); }

17. A program to find bigger number among three numbers.


#include<stdio.h> #include<conio.h>

void main() { int list[3],i,max; for(i=0; i<3; i++) { printf(" Enter the number"); scanf("%d",&list[i]); } max=list[0]; for(i=1;i<3;i++) { if(list[i]>max) max=list[i]; } printf("\n The bigger number is %d",max); getch(); }

18. A program to find the value of a quadratic equation.

#include<stdio.h> #include<conio.h> #include<math.h> void main()

{ int a,b,c; float d,root_1,root_2; clrscr(); printf("\n Enter values for a"); scanf("%d",&a); printf("\n Enter values for b"); scanf("%d",&b); printf("\n Enter values for c"); scanf("%d",&c); d=(b*b-4*a*c); if(d<0) printf("\n\n Roots are imaginary"); else { root_1=(-b+sqrt(d))/(2*a); root_2=(-b-sqrt(d))/(2*a); printf("\n\n x=%.4f,%.4f",root_1,root_2); } getch(); }

Das könnte Ihnen auch gefallen