A Personal Collection of CODE (C++) Turbo++ Shamim Mahmud Nazmul Hosen

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 30

A personal Collection of CODE (C++) turbo++

SHAMIM MAHMUD

NAZMUL HOSEN

#include<stdio.h>

void main()

int a;

scanf("%d",&a);

if (a%2==0)

printf("even");

else printf("odd");

/*programe to calculate addition*/

#include<stdio.h>

void main()

float a,b,total;

printf("First input=");

scanf("%f",&a);

printf("second input=");

scanf("%f",&b);

printf("Total=");
total=a-b;

printf("%f",total);

/*programe to calculate addition*/

#include<stdio.h>

void main()

float a,b,total;

printf("First input=");

scanf("%f",&a);

printf("second input=");

scanf("%f",&b);

printf("Total=");

total=a+b;

printf("%f",total);

#include<stdio.h>

void main()

printf("Hallo Nazmul");

}
1### Write down the CODE of following Equation

12+22+32+……+102=?

#include <stdio.h>

main ()

int i, sum=0;

for (i=1; i<=10; i=i+1) {

sum=sum+i*i;

printf ("%d", sum);

// write a two dimensional array and sum the elements of the array.

#include<stdio.h>

void main()

int a[2][3];

// enter your elements.

printf("Enter your array elements: ");

for(int i=0; i<2; i++)


for(int j=0; j<3; j++)

scanf("%d", & a[i][j]);

// print the array elements.

printf("\nPrint the array elements: \n");

for(int m=0; m<2; m++)

for(int n=0; n<3; n++)

printf("%3d ", a[m][n]);

printf("\n");

// write a program that inputs three characters and print their ascii value.

#include<stdio.h>

void main()

char a[3];

printf("Enter your three characters: ");

for(int i=0; i<3; i++)

scanf("%c", & a[i]);

}
printf("Print their ascii values: ");

for( int j=0; j<3; j++)

printf("%d ", a[j]);

// write a program that reads three characters.

#include<stdio.h>

void main()

char a[3];

printf("Enter three characters: ");

for(int i =0; i<3; i++)

scanf("%c", & a[i]);

// write a program that enters a name and print it in reverse order.

#include<stdio.h>

void main()

{
char a[4];

printf("Enter your name: ");

for(int i=0; i<4; i++)

scanf("%c", & a[i]);

// print the name;

printf("Print the name : ");

for(int j=0; j<4; j++)

printf("%c", a[j]);

// print the name in reverse order.

printf("\nprint the name in reverse order: ");

for(int k=3; k>=0; k--)

printf("%c", a[k]);

// write a program that enters a name and print it in reverse order.

#include<stdio.h>

void main()

char a[34];

printf("Enter a name: ");


gets(a);

// write a program that reads a name and print it in reverse way.

#include<stdio.h>

void main()

char ch[34];

int i, length=0;

printf("Enter your name :");

gets(ch); // like as scanf();

// print the name.

printf("\nprint the name: ");

puts(ch); // like as printf();

// find the length of the string.

for(i=0; ch[i]; i++)

length++;

printf("The lenght of the string is : %d", length);

// print the string in reverse order.

printf("\nPrint the name in reverse order: ");


for(int k=length-1; k>=0; k--)

printf("%c", ch[k]);

// write a program that sums a two dimentional array.

#include<stdio.h>

void main()

int a[2][3];

int sum=0;

// enter your elements.

printf("Enter your elements: \n");

for(int i=0; i<2; i++)

for(int j=0; j<3; j++)

scanf("%d", &a[i][j]);

sum = sum + a[i][j];

printf("\nThe sum of the numbers is : %d", sum);

}
// write a two dimensional array and sum the elements of the array.

#include<stdio.h>

void main()

int a[2][3];

// enter your elements.

printf("Enter your array elements: ");

for(int i=0; i<2; i++)

for(int j=0; j<3; j++)

scanf("%d", & a[i][j]);

// print the array elements.

printf("\nPrint the array elements: \n");

for(int m=0; m<2; m++)

for(int n=0; n<3; n++)

printf("%3d ", a[m][n]);

printf("\n");

#include<stdio.h>

#include<conio.h>
void main()

{float gpoint;

char gletter;

gletter=getch();

if(gletter=='*')gpoint=5;

else if(gletter=='A')gpoint=4.5;

else if(gletter=='b')gpoint=4;

else if(gletter=='B')gpoint=3.5;

else if(gletter=='F')gpoint=0.0;

printf("%f",gpoint);

#include<stdio.h>

void main()

char letter;

printf ("Enter a upper case value=");

scanf("%c",& letter);

if (letter>=65 & letter<=95)

printf ("Lower case value is=%c",letter+32);

#include<stdio.h>

void main()

{
float mark;

printf ("Please enter a mark=");

scanf("%f", & mark);

if (mark >=80)printf ("\nGet A+");

else if (mark >=70)printf ("\nGet A");

else if (mark >=55)printf ("\nGet B");

else if (mark >=40)printf ("\nGet C");

else printf ("\nGetF");

#include<stdio.h>

#include<conio.h>

void main()

char ch;

printf("\nenter a character=");

ch=getch();

switch(ch)

case'*':printf("5.0");break;

case'A':printf("4.0");break;

case'B':printf("3.0");break;

case'C':printf("2.0");break;
case'D':printf("1.0");break;

default:printf("0.0");break;

#include <stdio.h>

void main()

char letter;

printf ("Please enter a character =");

scanf("%c",& letter);

if (letter>=97 & letter <=127 )

printf("Upper case character is=%d",letter);

else if (letter >=65 & letter <=95)

printf ("Lower case character is =%d", letter);

#include <stdio.h>

void main()

char letter;

printf ("Please enter a character =");

scanf("%c",& letter);

if (letter>=97 & letter <=127 )

printf("Upper case character is=%d",letter);

else if (letter >=65 & letter <=95)

printf ("Lower case character is =%d", letter);


}

#include<stdio.h>

#include<conio.h>

void main()

{float gpoint;

char gletter;

gletter=getch();

if(gletter=='*')gpoint=5;

else if(gletter=='A')gpoint=4.5;

else if(gletter=='b')gpoint=4;

else if(gletter=='B')gpoint=3.5;

else if(gletter=='F')gpoint=0.0;

printf("%f",gpoint);

void main()

char ch;

printf ("please enter a character=" );

scanf("%c",& ch);
if (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')

printf ("\nYes it is a vowel");

else printf ("\nSorry it is a consonent");

#include <stdio.h>

void main()

char ch;

printf ("Please enter a character=");

scanf("%C",& ch );

switch (ch)

{case 'a':

case 'e':

case 'i':

case 'o':

case 'u': printf ("%c is Vowel, ch");}

defult : printf ("consonent");

#include <stdio.h>

void main()

char gl;

float gpa;

printf("Enter grade letter=");


scanf ("%c",& gl);

switch (gl)

{case '*':gpa=5.0;break;

case 'A':gpa=4.0;break;

case 'B':gpa=3.0;break;

case 'C':gpa=2.0;break;

defult : gpa=0.0;

printf ("GPA=%f",gpa);

#include<stdio.h>

#include<conio.h>

void main()

{float gpoint;

char gletter;

gletter=getch();

if(gletter=='*')gpoint=5;

else if(gletter=='A')gpoint=4.5;

else if(gletter=='b')gpoint=4;

else if(gletter=='B')gpoint=3.5;

else if(gletter=='F')gpoint=0.0;

printf("%f",gpoint);

}
1. addition*/

#include<stdio.h>

void main()

float a,b ,r;

printf("enter ur 1st number=");

scanf("%f",& a);

printf("enter ur 2nd number=");/* write a program which doing

scanf("%f",& b);

r=a+b;

printf("result=%f",r);

2. /* write a program which doing subtraction*/

#include<stdio.h>

void main()

float a,b ,r;

printf("enter ur 1st number=");

scanf("%f",& a);

printf("enter ur 2nd number=");

scanf("%f",& b);

r=a-b;

printf("result=%f",r);

}
3. /* write a program which doing maltiplication*/

#include<stdio.h>

void main()

float a,b ,r;

printf("enter ur 1st number=");

scanf("%f",& a);

printf("enter ur 2nd number=");

scanf("%f",& b);

r=a*b;

printf("result=%f",r);

4. /* write a program which doing divission*/

#include<stdio.h>

void main()

float a,b ,r;

printf("enter ur 1st number=");

scanf("%f",& a);

printf("enter ur 2nd number=");

scanf("%f",& b);

r=a/b;

printf("result=%f",r);

Control statement :
If statement & if else statement

1./*Write a program which determines the number is posative or negative*/

#include<stdio.h>

#include<conio.h>

void main()

int num;

printf ("number:");

scanf("%d",&num);

if(num<0)

printf("The number is negative");

else

printf("The number is posative");

2. /* write a program which determines the number is odd or even*/

#include<stdio.h>

void main()

int num;

printf ("Enter a number :");

scanf ("%d",& num);

if (num%2==0)

printf("The nuber is even");

else

printf("The number is odd");


}

3. /* write a program which determines the year is leap year or not */

#include<stdio.h>

void main()

int year;

printf ("Enter a year :");

scanf ("%d",& year);

if ((year % 4 == 0)||(year % 400 == 0) && (year % 100 != 0))

printf("The year is leap year");

else

printf("The year is not a leap year");

// program : if-sign.cpp

// mark the given number as a positive or negative.

#include <stdio.h>

main(void)

int num;

printf(" Number ? ");

scanf("%d",&num);
if(num<0)

printf(" Negative");

else

printf(" Positive");

return 0;

Odd or Even

#include<stdio.h>

void main()

int num;

printf("Enter a number");

scanf("%d",& num);

if(num%2==0)printf("number is even");

else printf("number is odd");

#include<stdio.h>

void main()

float a,b,total;

scanf("%f",&a);

scanf("%f",&b);

total=a+b;

printf("Total=%f",total);

}
#include <stdio.h>

void main()

float l,w,a;

scanf("%f",&l);

scanf("%f",&w);

a=l*w;

printf("Area=%f",a);

#include<stdio.h>

void main()

float radius,area;

scanf ("%f",&radius);

area=3.14*radius*radius;

printf("Area=%f",area);

// Programe name : oddEven

// Check whether a number is odd or even

// We'll use the conditional operartor

#include <stdio.h>

main()

{
int number;

printf("Enter a number? ");

scanf("%d",&number);

(number%2)==0?printf("\n Even"):printf("\n Odd");

return 0;

// program : toAscii.cpp

// Display the ASCII value of a given character

#include <stdio.h>

main(void)

char c;

printf(" Character ? ");

scanf("%c",&c);

printf(" %c -> %d",c,c);

return 0;

// Programe name : toUpper

// Convert a character to it's upper-form

// We'll use two additional library function : getche(), putch()


// These two functions are include the conio.h header file

#include <conio.h>

#include <stdio.h>

main()

{ char ch;

printf(" input characer ? ");

ch=getche();

ch=ch-32;

printf(" in uppercase : %c",ch);

return 0;

#include<stdio.h>

main()

float length,width,area;

scanf("%f",&length);

scanf("%f",&width);

area=length*width;

printf("area=%f",area);

return 0;

#include<stdio.h>
void main()

int a,b,c;

printf ("enter the three numbers\n");

scanf ("%d%d%d",&a,&b,&c);

if (a>b && a>c)

printf("%d is max",a);

else if(b<a && b>c)

printf("%d is max",c);

else printf("%d is max",c);

#include<stdio.h>

void main()

int mark;

printf ("enter the mark");

scanf ("%d",&mark);

if (mark>80) printf("a+");

else if (mark>75) printf("a");

#include<stdio.h>

void main()

{char array[]={'a','b','c','d'} ;

char array1[4];

for(int i=0;i<=3;i++)
array1[i]=array[i];

for(i=0;i<=3;i++)

array1[i]=array[3-i];

for(i=0;i<=3;i++)

printf("%c\n",array1[i]);

#include<stdio.h>

void main()

{char array[]={'a','b','c','d'} ;

char array1[4];

for(int i=0;i<=3;i++)

array1[i]=array[i];

for(i=0;i<=3;i++)

array[i]=array1[3-i];

for(i=0;i<=3;i++)

printf("%c\n",array[i]);

#include<stdio.h>

#include<math.h>

void main ()

{int n,b,flag;

flag=1;

scanf ("%d",&n);

b=sqrt(n);

for(int i=2;i<=b;i++)
{

if((n%i)==0)

{printf("this is not a prime number");

break;}

else{flag++;}

if(flag==b)printf("this is a prime number");

#include<stdio.h>

void main()

char array[]={'A','B','C','D'};

char array1[3];

int i;

for(i=0;i<=3;i++)

array1[i]=array[i]+32;

for(i=0;i<=3;i++)

printf("%c\n",array1[i]);

#include<stdio.h>

void main()

char array[]={'a','b','c','d'};

char array1[3];

int i;
for(i=0;i<=3;i++)

array1[i]=array[i]-32;

for(i=0;i<=3;i++)

printf("%c\n",array1[i]);

#include<stdio.h>

void main()

char array[]={'A','B','C','D'},t[4];

t[i]=array[i];

for(int i=0;i<=3;i++)

array[i]=t[3-i];

for(i=0;i<=3;i++)

printf("%c",array[i];

#include<stdio.h>

void main()

FILE*fp;

fp=fopen("shoiab","r");

int c;

fscanf(fp,"%d",&c);

fclose(fp);
fp=fopen("shoiab.write","w");

int i;

for(i=0;i<5;i++)

fprintf(fp,"%d\t",i*c);

if(i/5==0)fprintf(fp,"\n");

fclose(fp);

#include<stdio.h>

int to_upper_to_lower(int a)

if(a>=65 && a<=90) return a+32;

if(a>=97 && a<=122)return a-32;

void main()

char x,y;

scanf("%c",&y);

x=to_upper_to_lower( y);

printf("%c",x);

#include<stdio.h>

void main()

char array[]={'A','B','C','D'},t[4];
t[i]=array[i];

for(int i=0;i<=3;i++)

array[i]=t[3-i];

for(i=0;i<=3;i++)

printf("%c",array[i];

#include<stdio.h>

int factorial(int n)

if(n==1) return 1;

else return (n*factorial(n-1));

void main()

int x,y;

scanf("%d",&y);

x=factorial(y);

printf("%d",x);

#include<stdio.h>

int pow(int a, int b)

int i,mul=1;

for(i=1;i<=b;i++)
mul=mul*a;

void main ()

int n;

n= pow(2,3);

printf("%d",n);

NAZMUL HOSEN (CHE, SUST) SHAMIM MAHMUD (GEB, SUST)

17.06.2010

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy