#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int a,b;
main()
{
printf("Enter a Number :");
scanf("%d",&a);
b=0;
while(b <= a)
{
if ( b != 0 && b%2 == 1)
{
printf("\n%d",b);
}
b++;
}
getch();
}
1 to N Even Numbers [C/C++]
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int a,b;
main()
{
printf("Enter a Number :");
scanf("%d",&a);
b=0;
while(b <= a)
{
if ( b != 0 && b%2 == 0)
{
printf("\n%d",b);
}
b++;
}
getch();
}
#include<conio.h>
#include<stdlib.h>
int a,b;
main()
{
printf("Enter a Number :");
scanf("%d",&a);
b=0;
while(b <= a)
{
if ( b != 0 && b%2 == 0)
{
printf("\n%d",b);
}
b++;
}
getch();
}
Count the number of letter [C/C++]
#include<iostream>
#include<string>
using namespace std;
void main()
{
char c;
string str;
int len, count = 0;
cout << "Type the word you want: ";
getline(cin,str);
cout << "Type the letter you want to count: ";
cin >> c;
len = str.length();
for (int ctr = 0; ctr < len; ctr++)
{
if (str.at(ctr) == c)
{
count = count + 1;
}
}
cout << "\n";
cout << "There are " << count << " letters in " << str << endl;
}
#include<string>
using namespace std;
void main()
{
char c;
string str;
int len, count = 0;
cout << "Type the word you want: ";
getline(cin,str);
cout << "Type the letter you want to count: ";
cin >> c;
len = str.length();
for (int ctr = 0; ctr < len; ctr++)
{
if (str.at(ctr) == c)
{
count = count + 1;
}
}
cout << "\n";
cout << "There are " << count << " letters in " << str << endl;
}
Magic Square Odd Numbers Only [C/C++]
#include <iostream.h>
int main()
{
int magic[100][100];
int i, j, n, x, y;
for ( i=0 ; i<100; i++ )
for ( j=0 ; j<100 ; j++ )
magic[i][j] = 0;
cout << "Enter value for n (odd only): ";
cin >> n;
x = 0 ; y = (n-1) / 2;
magic[x][y] = 1;
for ( i=2 ; i <= n*n ; i++ )
{
x--; y++;
if ( x < 0 && y == n )
{
x = x + 2;
y--;
}
if ( x < 0 ) { x = n - 1; }
if ( y >= n ) { y = 0; }
if ( magic[x][y] != 0 )
{
x = x + 2;
y = y - 1;
}
magic[x][y] = i;
}
for ( i = 0 ; i < n ; i++ )
{
for ( j = 0 ; j < n ; j++ )
{
cout << magic[i][j] << "\t";
}
cout << endl;
}
return 0;
}
int main()
{
int magic[100][100];
int i, j, n, x, y;
for ( i=0 ; i<100; i++ )
for ( j=0 ; j<100 ; j++ )
magic[i][j] = 0;
cout << "Enter value for n (odd only): ";
cin >> n;
x = 0 ; y = (n-1) / 2;
magic[x][y] = 1;
for ( i=2 ; i <= n*n ; i++ )
{
x--; y++;
if ( x < 0 && y == n )
{
x = x + 2;
y--;
}
if ( x < 0 ) { x = n - 1; }
if ( y >= n ) { y = 0; }
if ( magic[x][y] != 0 )
{
x = x + 2;
y = y - 1;
}
magic[x][y] = i;
}
for ( i = 0 ; i < n ; i++ )
{
for ( j = 0 ; j < n ; j++ )
{
cout << magic[i][j] << "\t";
}
cout << endl;
}
return 0;
}
C and C++ E-Books
"C++" E-Books
- Applied C++ - Practical Techniques For Building Better Software (2003).chm
- Beginning C++ Game Programming (2004).pdf
- Beyond The C++ Standard Library - An Introduction To Boost (2005).chm
- C++ - How To Program, 5th Edition (2005).chm
- C++ By Dissection (2002).pdf
- C++ Coding Standards - 101 Rules, Guidelines, And Best Practices (2004).chm
- C++ Cookbook (2005).chm
- C++ Demystified - A Self Teaching Guide (2004).chm
- C++ For Business Programming, 2nd Edition (2005).chm
- C++ For Dummies, 5th Edition (2004).pdf
- C++ For Mathematicians - An Introduction For Students And Professionals (2006).pdf
- C++ From The Ground Up, 3rd Edition (2003).pdf
- C++ GUI Programming With Qt 4 (2006).chm
- C++ In A Nutshell (2003).chm
- C++ Plus Data Structures, 3rd Edition (2003).pdf
- C++ Primer, 4th Edition (2005).chm
- C++ Templates - The Complete Guide (2002).chm
- C++ Timesaving Techniques For Dummies (2005).pdf
- C++ Tutorial By Clayman.html
- c++ tutorial.pdf
- C-C++ Programmer's Reference, 3rd Edition (2003).chm
- Creating Games In C++ - A Step By Step Guide (2006).chm
- Cryptography In C And C++ (2001).chm
- Effective C++, 3rd Edition (2005).chm
- Exceptional C++ - 47 Engineering Puzzles, Programming Problems, And
- Solutions (1999).chm
- Exceptional C++ Style - 40 New Engineering Puzzles, Programming
- Problems, And Solutions (2004).chm
- How Not To Program In C++ (2003).chm
- Ivor Horton's Beginning Visual C++ 2005 (2006).pdf
- Learn To Program With C++ (2003).pdf
- McGraw Hill Herb Schildts C plus plus Programming Cookbook Apr 2008.pdf
- Packt Publishing Microsoft Visual C++ Windows Applications by Example Jun 2008.pdf
- Teach Yourself C++ in 21 Days
- think in cpp.pdf
- Visual C++ 6 for Dummies Quick Reference.pdf
- BASIC C Socket Programming In Unix For Newbies.txt
- C & C++ Programming Style Guidlines.pdf
- C for Dummies, 2nd Edition.pdf
- Sams Teach Yourself Visual C Sharp 2008 in 24 Hours Complete Starter Kit Jul 2008.pdf
- The C Programming Language Torn Apart.html
-
Guessing Game [C/C++]
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<iostream>
main()
{
int a,b,c,d,e,f,f1,points,ctr;
do{
system("cls");
system("color 6");
srand(time(NULL));
b=1+rand()%10;
ctr=3;
e=b;
system("cls");
do{
printf("Guess a Number: ");
scanf("%d",&a);
if(a>b)
{
printf("Lower Please!!\n");
}
if(a<b)
{
printf("Higher Please!!\n");
}
ctr--;
if( ctr==2)
{
points=15;
}
if( ctr==1)
{
points=10;
}
if( ctr==0)
{
points=5;
}
if(a == b)
{
system("color 7");
printf("\n\nExcellent You Got it!!\n");
printf("Your Score is %d\n",points);
}
}while(a!=b && ctr!=0);
if(a!=b && ctr==0)
{
system("color 4");
printf("\n\nYou did not Get it !! \n%d is the Number!!",e);
printf("Your Score is 0");
}
printf("\n\n\nTry Again ? 1=Yes 2=No");
scanf("%d",&d);
if(d==1)
{
ctr+3;
}
if(d==2)
{
break;
}
}while(1);
return(0);
}
#include<conio.h>
#include<stdlib.h>
#include<iostream>
main()
{
int a,b,c,d,e,f,f1,points,ctr;
do{
system("cls");
system("color 6");
srand(time(NULL));
b=1+rand()%10;
ctr=3;
e=b;
system("cls");
do{
printf("Guess a Number: ");
scanf("%d",&a);
if(a>b)
{
printf("Lower Please!!\n");
}
if(a<b)
{
printf("Higher Please!!\n");
}
ctr--;
if( ctr==2)
{
points=15;
}
if( ctr==1)
{
points=10;
}
if( ctr==0)
{
points=5;
}
if(a == b)
{
system("color 7");
printf("\n\nExcellent You Got it!!\n");
printf("Your Score is %d\n",points);
}
}while(a!=b && ctr!=0);
if(a!=b && ctr==0)
{
system("color 4");
printf("\n\nYou did not Get it !! \n%d is the Number!!",e);
printf("Your Score is 0");
}
printf("\n\n\nTry Again ? 1=Yes 2=No");
scanf("%d",&d);
if(d==1)
{
ctr+3;
}
if(d==2)
{
break;
}
}while(1);
return(0);
}
Area of Rectangle Calculator [C/C++]
#include<stdio.h>
#include<conio.h>
main()
{
int length,width,area;
printf("Enter the Lenght of a rectangle:");
scanf("%d",&length);
printf("\nEnter the Width of a rectangle:");
scanf("%d",&width);
area = length*width;
printf("\n\n\n\nThe Area of the Rectangle is %d",area);
getch();
}
#include<conio.h>
main()
{
int length,width,area;
printf("Enter the Lenght of a rectangle:");
scanf("%d",&length);
printf("\nEnter the Width of a rectangle:");
scanf("%d",&width);
area = length*width;
printf("\n\n\n\nThe Area of the Rectangle is %d",area);
getch();
}
Simple Time Converter [C/C++]
#include<stdio.h>
#include<conio.h>
int a,b,c,d;
main()
{
printf("****************************************\n");
printf("* Time Conversion *\n");
printf("* *\n");
printf("* 1] 60 secs = 1 min *\n");
printf("* 2] 60 min = 1 hour *\n");
printf("* *\n");
printf("****************************************\n");
printf("Input 1 for sec to min ; 2 for min to hour: ");
/*dL1nkx*/
scanf("%d",&a);
if ( a == 1)
{/*dL1nkx*/
printf("\n\nPlease Enter SECONDS: ");
scanf("%d",&b);
c = b/60;
d = b%60;
printf("\nIn %d secs there are %d min and %d secs ",b,c,d);
}/*dL1nkx*/
if ( a == 2)
{
printf("\n\nPlease Enter MINUTES: ");
scanf("%d",&b);
c = b/60;
d = b%60;
printf("\nIn %d mins there are %d hour and %d mins ",b,c,d);
}
if (a != 1 && a!=2)
{
printf("Please Enter 1 or 2 Only");/*dL1nkx*/
}
getch();
}
#include<conio.h>
int a,b,c,d;
main()
{
printf("****************************************\n");
printf("* Time Conversion *\n");
printf("* *\n");
printf("* 1] 60 secs = 1 min *\n");
printf("* 2] 60 min = 1 hour *\n");
printf("* *\n");
printf("****************************************\n");
printf("Input 1 for sec to min ; 2 for min to hour: ");
/*dL1nkx*/
scanf("%d",&a);
if ( a == 1)
{/*dL1nkx*/
printf("\n\nPlease Enter SECONDS: ");
scanf("%d",&b);
c = b/60;
d = b%60;
printf("\nIn %d secs there are %d min and %d secs ",b,c,d);
}/*dL1nkx*/
if ( a == 2)
{
printf("\n\nPlease Enter MINUTES: ");
scanf("%d",&b);
c = b/60;
d = b%60;
printf("\nIn %d mins there are %d hour and %d mins ",b,c,d);
}
if (a != 1 && a!=2)
{
printf("Please Enter 1 or 2 Only");/*dL1nkx*/
}
getch();
}
Simple Time Converter [C/C++]
#include<stdio.h>
#include<conio.h>
int a,b,c,d;
main()
{
printf("****************************************\n");
printf("* Time Conversion *\n");
printf("* *\n");
printf("* 1] 60 secs = 1 min *\n");
printf("* 2] 60 min = 1 hour *\n");
printf("* *\n");
printf("****************************************\n");
printf("Input 1 for sec to min ; 2 for min to hour: ");
/*dL1nkx*/
scanf("%d",&a);
if ( a == 1)
{/*dL1nkx*/
printf("\n\nPlease Enter SECONDS: ");
scanf("%d",&b);
c = b/60;
d = b%60;
printf("\nIn %d secs there are %d min and %d secs ",b,c,d);
}/*dL1nkx*/
if ( a == 2)
{
printf("\n\nPlease Enter MINUTES: ");
scanf("%d",&b);
c = b/60;
d = b%60;
printf("\nIn %d mins there are %d hour and %d mins ",b,c,d);
}
if (a != 1 && a!=2)
{
printf("Please Enter 1 or 2 Only");/*dL1nkx*/
}
getch();
}
#include<conio.h>
int a,b,c,d;
main()
{
printf("****************************************\n");
printf("* Time Conversion *\n");
printf("* *\n");
printf("* 1] 60 secs = 1 min *\n");
printf("* 2] 60 min = 1 hour *\n");
printf("* *\n");
printf("****************************************\n");
printf("Input 1 for sec to min ; 2 for min to hour: ");
/*dL1nkx*/
scanf("%d",&a);
if ( a == 1)
{/*dL1nkx*/
printf("\n\nPlease Enter SECONDS: ");
scanf("%d",&b);
c = b/60;
d = b%60;
printf("\nIn %d secs there are %d min and %d secs ",b,c,d);
}/*dL1nkx*/
if ( a == 2)
{
printf("\n\nPlease Enter MINUTES: ");
scanf("%d",&b);
c = b/60;
d = b%60;
printf("\nIn %d mins there are %d hour and %d mins ",b,c,d);
}
if (a != 1 && a!=2)
{
printf("Please Enter 1 or 2 Only");/*dL1nkx*/
}
getch();
}
Guessing Game with Level [C/C++]
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,d,e,f,f1,points,ctr;
do{
system("cls");
system("color 6");
system("cls");
do{
system("cls");
printf("Guessing Game\n");
/*dL1nk*/
printf("Level 1 = 1-10\n");
/*dL1nk*/
printf("Level 2 = 1-20\n");
printf("Level 3 = 1-30\n");
/*dL1nk*/
printf("Level 4 = 1-40\n");
printf("Level 5 = 1-50\n");
printf("\n\nPlease Enter Level ==>");
scanf("%d",&e);
if( e==1)
{
f=10;
f1=1;
}
if( e==2)
{
f=30;
f1=2;
}
if( e==3)
{
/*dL1nk*/
f=30;
f1=3;
}
if( e==4)
{
f=40;
f1=4;
}
if( e==5)
/*dL1nk*/
{
f=50;
f1=5;
}
if( e>5)
{
system("cls");
}
}while(e!=1 && e!=2 && e!=3 && e!=4 && e!=5);
srand(time(NULL));
/*dL1nk*/
b=1+rand()%f;
ctr=3;
e=b;
/*dL1nk*/
system("cls");
do{
printf("\nGuess a Number: ");
scanf("%d",&a);
if(a>b)
{
printf("Lower Please!!\n");
}
/*dL1nk*/
if(a<b)
{
printf("Higher Please!!\n");
}
/*dL1nk*/
ctr--;
if( ctr==2)
{
points=15;
}
if( ctr==1)
{
points=10;
}
if( ctr==0)
{
points=5;
}
if(a == b)
/*dL1nk*/
{
system("color 7");
printf("\n\nExcellent You Got it!!\n");
printf("Your Score is %d\n",points);
printf("\nLevel of Difficluty %d = 1-%d",f1,f);
}
}while(a!=b && ctr!=0);
if(a!=b && ctr==0)
{
system("color b");
printf("\n\nYou did not Get it !! \n%d is the Number!!\n",e);
printf("Level of Difficluty %d = 1-%d",f1,f);
/*dL1nk*/
printf("\nYour Score is 0");
}
printf("\n\nTry Again ? 1=Yes 2=No ==>> ");
scanf("%d",&d);
/*dL1nk*/
if(d==1)
{
ctr+3;
}
if(d==2)
/*dL1nk*/
{
break;
}
}while(1);
/*dL1nk*/
return(0);
}
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,d,e,f,f1,points,ctr;
do{
system("cls");
system("color 6");
system("cls");
do{
system("cls");
printf("Guessing Game\n");
/*dL1nk*/
printf("Level 1 = 1-10\n");
/*dL1nk*/
printf("Level 2 = 1-20\n");
printf("Level 3 = 1-30\n");
/*dL1nk*/
printf("Level 4 = 1-40\n");
printf("Level 5 = 1-50\n");
printf("\n\nPlease Enter Level ==>");
scanf("%d",&e);
if( e==1)
{
f=10;
f1=1;
}
if( e==2)
{
f=30;
f1=2;
}
if( e==3)
{
/*dL1nk*/
f=30;
f1=3;
}
if( e==4)
{
f=40;
f1=4;
}
if( e==5)
/*dL1nk*/
{
f=50;
f1=5;
}
if( e>5)
{
system("cls");
}
}while(e!=1 && e!=2 && e!=3 && e!=4 && e!=5);
srand(time(NULL));
/*dL1nk*/
b=1+rand()%f;
ctr=3;
e=b;
/*dL1nk*/
system("cls");
do{
printf("\nGuess a Number: ");
scanf("%d",&a);
if(a>b)
{
printf("Lower Please!!\n");
}
/*dL1nk*/
if(a<b)
{
printf("Higher Please!!\n");
}
/*dL1nk*/
ctr--;
if( ctr==2)
{
points=15;
}
if( ctr==1)
{
points=10;
}
if( ctr==0)
{
points=5;
}
if(a == b)
/*dL1nk*/
{
system("color 7");
printf("\n\nExcellent You Got it!!\n");
printf("Your Score is %d\n",points);
printf("\nLevel of Difficluty %d = 1-%d",f1,f);
}
}while(a!=b && ctr!=0);
if(a!=b && ctr==0)
{
system("color b");
printf("\n\nYou did not Get it !! \n%d is the Number!!\n",e);
printf("Level of Difficluty %d = 1-%d",f1,f);
/*dL1nk*/
printf("\nYour Score is 0");
}
printf("\n\nTry Again ? 1=Yes 2=No ==>> ");
scanf("%d",&d);
/*dL1nk*/
if(d==1)
{
ctr+3;
}
if(d==2)
/*dL1nk*/
{
break;
}
}while(1);
/*dL1nk*/
return(0);
}
Palindrome [C/C++]
//Coded by : dL1nkx
//Copyright: dL1nkx.blogspot.com
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char o[15],p[15],q[15];
printf("Please Enter a Word ");
scanf("%s",o);
strcpy(p,strrev(o));
printf("%s",strrev(o));
if(strcmpi(o,p) == 0)
printf("\nIt is Palindrome");
else
printf("\nNot Palindrome");
getch();
}
//Copyright: dL1nkx.blogspot.com
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char o[15],p[15],q[15];
printf("Please Enter a Word ");
scanf("%s",o);
strcpy(p,strrev(o));
printf("%s",strrev(o));
if(strcmpi(o,p) == 0)
printf("\nIt is Palindrome");
else
printf("\nNot Palindrome");
getch();
}
Factorial of a Number [C/C++]
//Coded by : dL1nkx
//Copyright: dL1nkx.blogspot.com
#include<stdio.h>
int main ()
{
int i,num,factorial=1;
printf("ENTER THE NUMBER");
scanf("%d",&num);
if(num<0)
printf("Factorial not possible");
else
{
for (i=1;i<=num;i++)
{factorial=factorial*i;}
printf("\nFACTORIAL=%d\n",factorial);
}
return 0;
}
//Copyright: dL1nkx.blogspot.com
#include<stdio.h>
int main ()
{
int i,num,factorial=1;
printf("ENTER THE NUMBER");
scanf("%d",&num);
if(num<0)
printf("Factorial not possible");
else
{
for (i=1;i<=num;i++)
{factorial=factorial*i;}
printf("\nFACTORIAL=%d\n",factorial);
}
return 0;
}
Factors of a Number [C/C++]
//Coded by : dL1nkx
//Copyright: dL1nkx.blogspot.com
#include <stdio.h>
int main()
{
int x,y,z;
printf("enter the number: ");
scanf("%d",&x);
printf("The factors are as follow:\n");
for (y=1;y<=x;y++)
{ if (x%y==0)
printf("%d\n",y);}// loop end
return 0;
}
//Copyright: dL1nkx.blogspot.com
#include <stdio.h>
int main()
{
int x,y,z;
printf("enter the number: ");
scanf("%d",&x);
printf("The factors are as follow:\n");
for (y=1;y<=x;y++)
{ if (x%y==0)
printf("%d\n",y);}// loop end
return 0;
}
ASCII code way 2 [C/C++]
//Coded by : dL1nkx
//Copyright: dL1nkx.blogspot.com
#include<stdio.h>
int main()
{
int x;
char character;
printf("ENTER THE CHARACTER\n");
scanf("%c",&character);
x=character;
printf("THE ASCII VALUE OF %c is %d\n",character,x);
return 0;
}
//Copyright: dL1nkx.blogspot.com
#include<stdio.h>
int main()
{
int x;
char character;
printf("ENTER THE CHARACTER\n");
scanf("%c",&character);
x=character;
printf("THE ASCII VALUE OF %c is %d\n",character,x);
return 0;
}
ASCII codes way1 [C/C++]
//Coded by : dL1nkx
//Copyright: dL1nkx.blogspot.com
#include<stdio.h>
int main()
{
int z;
printf("ENTER THE CHARACTER\n");
z=getchar();
printf("THE ASCII VALUE OF CHARACTER is %d\n",z);
return 0;
}
//Copyright: dL1nkx.blogspot.com
#include<stdio.h>
int main()
{
int z;
printf("ENTER THE CHARACTER\n");
z=getchar();
printf("THE ASCII VALUE OF CHARACTER is %d\n",z);
return 0;
}
Grade Calculator (5 Subjects) [C/C++]
//Coded by : dL1nkx
//Copyright: dL1nkx.blogspot.com
#include<stdio.h>
int main () {
int sub1,sub2,sub3,sub4,sub5,total;
float average;
printf("ENTER THE NUMBERS IN 5 SUBJECTS OF THE STUDENT\n");
scanf("%d%d%d%d%d",&sub1,&sub2,&sub3,&sub4,&sub5);
total=sub1+sub2+sub3+sub4+sub5;
average=total/5;
if(average>=80)
{printf("STUDENT HAS GOT A GRADE\n");}
else if(average>=70)
{printf("STUDENT HAS GOT B GRADE\n");}
else if(average >=60)
{printf("STUDENT HAS GOT C GRADE\n");}
else if(average>=50)
{printf("STUDENT HAS GOT D GRADE\n");}
else if(average>=40)
{printf("STUDENT HAS GOT E GRADE\n");}
else
{printf("STUDENT HAS FOT F GRADE\n");}
return 0;
}
//Copyright: dL1nkx.blogspot.com
#include<stdio.h>
int main () {
int sub1,sub2,sub3,sub4,sub5,total;
float average;
printf("ENTER THE NUMBERS IN 5 SUBJECTS OF THE STUDENT\n");
scanf("%d%d%d%d%d",&sub1,&sub2,&sub3,&sub4,&sub5);
total=sub1+sub2+sub3+sub4+sub5;
average=total/5;
if(average>=80)
{printf("STUDENT HAS GOT A GRADE\n");}
else if(average>=70)
{printf("STUDENT HAS GOT B GRADE\n");}
else if(average >=60)
{printf("STUDENT HAS GOT C GRADE\n");}
else if(average>=50)
{printf("STUDENT HAS GOT D GRADE\n");}
else if(average>=40)
{printf("STUDENT HAS GOT E GRADE\n");}
else
{printf("STUDENT HAS FOT F GRADE\n");}
return 0;
}
Subscribe to:
Posts (Atom)