Isosceles Triangle:
#include<stdio.h>
#include<conio.h>
int main()
{
int cntro,cntra,cntri, height=0;
printf("Enter height of pyramid: ");
scanf("%i",&height);
for(cntro=1;cntro<=height;cntro++) { for(cntri=height;cntri>cntro;cntri–)
printf(" ");
for(cntra=1;cntra<=cntro;cntra++)
printf("* ");
printf("\n");
}
getch();
return 0;
}
OUTPUT:
(A TRIANGLE OF ASTERISK(*))
A C++ Right Triangle Program
The Famous Right Triangle Program:
#include<stdio.h>
#include<conio.h>
main()
{
int height, counter, cntra;
printf("Enter height of triangle: ");
scanf("%i", &height);
for (counter=1; counter<=height; counter++) { for(cntra=1;cntra<=counter; cntra++)
printf("*");
printf("\n");
}
getch();
return 0;
}
OUTPUT:
*
**
***
****
#include<stdio.h>
#include<conio.h>
main()
{
int height, counter, cntra;
printf("Enter height of triangle: ");
scanf("%i", &height);
for (counter=1; counter<=height; counter++) { for(cntra=1;cntra<=counter; cntra++)
printf("*");
printf("\n");
}
getch();
return 0;
}
OUTPUT:
*
**
***
****
Temperature Conversion Program in C++
A C++ Program That converts Temperatures:
#include<stdio.h>
#include<conio.h>
int main()
{
float temp_fahrenheit, temp_celsius;
char option=’ ‘;
printf("\n Choose type of conversion:");
printf("\n\t[F]ahrenheit to Celsius");
printf("\n\t[C]elsius to Fahrenheit");
printf("\nEnter option: ");
scanf("%c",&option);
switch(option)
{
case ‘F’: case ‘f’:
printf("Enter temperature value in Fahrenheit: ");
scanf("%f",&temp_fahrenheit);
temp_celsius = (temp_fahrenheit – 32) * 5/9;
printf("%.2f degrees Fahrenheit is equal to %.2f degrees Celsius", temp_fahrenheit, temp_celsius);
break;
case ‘C’: case ‘c’:
printf("Enter temperature value in Celsius: ");
scanf("%f",&temp_celsius);
temp_fahrenheit = (temp_celsius * 9/5)+ 32;
printf("%.2Lf degrees Celsius is equal to %.2f degrees Fahrenheit", temp_celsius, temp_fahrenheit);
break;
default:
printf("Unknown option selected.");
break;
}
printf("\nExiting …");
getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
int main()
{
float temp_fahrenheit, temp_celsius;
char option=’ ‘;
printf("\n Choose type of conversion:");
printf("\n\t[F]ahrenheit to Celsius");
printf("\n\t[C]elsius to Fahrenheit");
printf("\nEnter option: ");
scanf("%c",&option);
switch(option)
{
case ‘F’: case ‘f’:
printf("Enter temperature value in Fahrenheit: ");
scanf("%f",&temp_fahrenheit);
temp_celsius = (temp_fahrenheit – 32) * 5/9;
printf("%.2f degrees Fahrenheit is equal to %.2f degrees Celsius", temp_fahrenheit, temp_celsius);
break;
case ‘C’: case ‘c’:
printf("Enter temperature value in Celsius: ");
scanf("%f",&temp_celsius);
temp_fahrenheit = (temp_celsius * 9/5)+ 32;
printf("%.2Lf degrees Celsius is equal to %.2f degrees Fahrenheit", temp_celsius, temp_fahrenheit);
break;
default:
printf("Unknown option selected.");
break;
}
printf("\nExiting …");
getch();
return 0;
}
C++ Calendar
A C Programming Exercise using Program Control
Structures
#include<stdio.h>
#include<conio.h>
int main()
{
unsigned int day=0, month=0, year=0, f_day=0, f_month=0, f_year=0;
int invalid_input=0, invalid_date=0;
char response=’y';
while (response==’Y'||response==’y')
{
printf("Enter date [dd mm yyyy]: ");
scanf("%i %i %i", &day, &month, &year);
if (day<1)
invalid_input++;
if (month<1 || month>12)
invalid_input++;
if (year<1)
invalid_input++;
switch (month)
{
case 1: case 3: case 5: case 7: case 8: case 10:
if (day>31)
invalid_date++;
else
{
if(day==31)
{
f_day=1;
f_month=month+1;
}
else
{
f_day=day+1;
f_month=month;
}
}
f_year=year;
break;
case 12:
if (day>31)
invalid_date++;
else
{
if(day==31)
{
f_day=1;
f_month=1;
f_year=year+1;
}
else
{
f_day=day+1;
f_month=month;
f_year=year;
}
}
break;
case 4: case 6: case 9: case 11:
if (day>30)
invalid_date++;
else
{
if(day==30)
{
f_day=1;
f_month=month+1;
}
else
{
f_day=day+1;
f_month=month;
}
}
f_year=year;
break;
case 2:
if(year%4==0)
{
if (day>29)
invalid_date++;
else
{
if(day==29)
{
f_day=1;
f_month=month+1;
}
else
{
f_day=day+1;
f_month=month;
}
}
}
else
{
if (day>28)
invalid_date++;
else
{
if(day==28)
{
f_day=1;
f_month=month+1;
}
else
{
f_day=day+1;
f_month=month;
}
}
}
f_year=year;
break;
}
if (invalid_input>0)
printf("INVALID INPUT!!!!");
else if (invalid_date>0)
printf("INVALID DATE!!!!");
else
{
printf("Date following ");
if (day<10)
printf("0");
printf("%i:",day);
if (month<10)
printf("0");
printf("%i:",month);
if (year<10)
printf("000");
if (year>10 && year<100)
printf("00");
if (year>100 && year<1000)
printf("0");
printf("%i",year);
printf(" is ");
if (f_day<10)
printf("0");
printf("%i:",f_day);
if (f_month<10)
printf("0");
printf("%i:",f_month);
if (f_year<10)
printf("000");
if (f_year>10 && f_year<100)
printf("00");
if (f_year>100 && f_year<1000)
printf("0");
printf("%i.",f_year);
}
printf("\nRetry[Y/N]:");
scanf("%s",&response);
fflush(stdin);
}
getch();
return 0;
}
Structures
#include<stdio.h>
#include<conio.h>
int main()
{
unsigned int day=0, month=0, year=0, f_day=0, f_month=0, f_year=0;
int invalid_input=0, invalid_date=0;
char response=’y';
while (response==’Y'||response==’y')
{
printf("Enter date [dd mm yyyy]: ");
scanf("%i %i %i", &day, &month, &year);
if (day<1)
invalid_input++;
if (month<1 || month>12)
invalid_input++;
if (year<1)
invalid_input++;
switch (month)
{
case 1: case 3: case 5: case 7: case 8: case 10:
if (day>31)
invalid_date++;
else
{
if(day==31)
{
f_day=1;
f_month=month+1;
}
else
{
f_day=day+1;
f_month=month;
}
}
f_year=year;
break;
case 12:
if (day>31)
invalid_date++;
else
{
if(day==31)
{
f_day=1;
f_month=1;
f_year=year+1;
}
else
{
f_day=day+1;
f_month=month;
f_year=year;
}
}
break;
case 4: case 6: case 9: case 11:
if (day>30)
invalid_date++;
else
{
if(day==30)
{
f_day=1;
f_month=month+1;
}
else
{
f_day=day+1;
f_month=month;
}
}
f_year=year;
break;
case 2:
if(year%4==0)
{
if (day>29)
invalid_date++;
else
{
if(day==29)
{
f_day=1;
f_month=month+1;
}
else
{
f_day=day+1;
f_month=month;
}
}
}
else
{
if (day>28)
invalid_date++;
else
{
if(day==28)
{
f_day=1;
f_month=month+1;
}
else
{
f_day=day+1;
f_month=month;
}
}
}
f_year=year;
break;
}
if (invalid_input>0)
printf("INVALID INPUT!!!!");
else if (invalid_date>0)
printf("INVALID DATE!!!!");
else
{
printf("Date following ");
if (day<10)
printf("0");
printf("%i:",day);
if (month<10)
printf("0");
printf("%i:",month);
if (year<10)
printf("000");
if (year>10 && year<100)
printf("00");
if (year>100 && year<1000)
printf("0");
printf("%i",year);
printf(" is ");
if (f_day<10)
printf("0");
printf("%i:",f_day);
if (f_month<10)
printf("0");
printf("%i:",f_month);
if (f_year<10)
printf("000");
if (f_year>10 && f_year<100)
printf("00");
if (f_year>100 && f_year<1000)
printf("0");
printf("%i.",f_year);
}
printf("\nRetry[Y/N]:");
scanf("%s",&response);
fflush(stdin);
}
getch();
return 0;
}
Slow Loading Computer - Make My PC Run Faster
A slow computer is obviously a serious charge. Many people wonder: "How can I make my PC run faster?
Unfortunately, since it is a popular problem, each brother and their 2 cents, he is wiling to how to fix it.
And since not a single appropriation for each system to work, he may find a real nightmare to know what to do. To help you cut through the chaos, here are 3 tips you can apply immediately.
TIP # 1) eliminate trash ""
Just get rid of words - the unnecessary programs that you do not need. Above all, focus on start-up "automatic" programs, which, if the computer does not start.
Often when you download files, they have a default setting that they start to self-imposed system. All this consumes a huge amount of RAM.
Either get rid of it completely, or ...
Simply turn the function that starts automatically led. I recommend the latter if you have not eaten over the last 6 months.
Unfortunately, since it is a popular problem, each brother and their 2 cents, he is wiling to how to fix it.
And since not a single appropriation for each system to work, he may find a real nightmare to know what to do. To help you cut through the chaos, here are 3 tips you can apply immediately.
TIP # 1) eliminate trash ""
Just get rid of words - the unnecessary programs that you do not need. Above all, focus on start-up "automatic" programs, which, if the computer does not start.
Often when you download files, they have a default setting that they start to self-imposed system. All this consumes a huge amount of RAM.
Either get rid of it completely, or ...
Simply turn the function that starts automatically led. I recommend the latter if you have not eaten over the last 6 months.
Ways to Speed Up Your Computer in 60 Minutes Or Less
What are the 5 best ways to speed up your computer performance? There are great people who work and they are here.
Step # 1) Get rid of "automatic" loading programs
This could be the most important step of all. These things are killers. Believe it or not, many of these things you've downloaded forget 2 years ago - and everything that starts automatically with your system.
Obviously, most current programs ... be slower to boot the PC and eventually executed. I guarantee you that you're eliminating 90% of environmental impacts and none of the poor.
Step # 2) Increase your RAM
It is superfluous ... But by removing all unused files from your hard drive is one of the most effective methods to increase system performance. More memory is available, the proper functioning of all.
But all my files are important!
Step # 1) Get rid of "automatic" loading programs
This could be the most important step of all. These things are killers. Believe it or not, many of these things you've downloaded forget 2 years ago - and everything that starts automatically with your system.
Obviously, most current programs ... be slower to boot the PC and eventually executed. I guarantee you that you're eliminating 90% of environmental impacts and none of the poor.
Step # 2) Increase your RAM
It is superfluous ... But by removing all unused files from your hard drive is one of the most effective methods to increase system performance. More memory is available, the proper functioning of all.
But all my files are important!
Divisors of a Number in C
A program in c++ where the user inputs a whole number.If the number inputted is negative,it will display, “Input Error!!”. But if the number is positive,then it would display its divisors.
#include<stdio.h> //preprocessor directive
#include<conio.h>
int main()
{
long int numb=0,divisor=1;
printf("\nInput a whole number:");
scanf("%li",&numb);
if(numb<=0)
printf("\nInvalid Input!!");
else
{
printf("The divisors of %li are ",numb);
for(divisor=1; (divisor<=numb);divisor++)
{
if (divisor==1)
{
printf("%li",divisor);
continue;
}
if(divisor==numb)
printf(" and %li.",divisor);
else if(numb%divisor==0)
printf(", %li",divisor);
else
continue;
}
}
getch();
return 0;
}
#include<stdio.h> //preprocessor directive
#include<conio.h>
int main()
{
long int numb=0,divisor=1;
printf("\nInput a whole number:");
scanf("%li",&numb);
if(numb<=0)
printf("\nInvalid Input!!");
else
{
printf("The divisors of %li are ",numb);
for(divisor=1; (divisor<=numb);divisor++)
{
if (divisor==1)
{
printf("%li",divisor);
continue;
}
if(divisor==numb)
printf(" and %li.",divisor);
else if(numb%divisor==0)
printf(", %li",divisor);
else
continue;
}
}
getch();
return 0;
}
Subscribe to:
Posts (Atom)