Tuesday, May 7, 2013

C Program to print 1-100 using for loop

The Program given below is a C++ Program to show 1 to 100 in the Output. I have used for loop to print 1-100 on the screen. You may also print any set of number of a fixed interval. For example you may print 3, 6, 9.....27. If you want to do so then need to replace the 5th line by for(i=3; i<=27; i=i+3). Thus you may print any of your expected set of number of same interval.
#include<stdio.h>
void main()
{
int i;
for(i=1; i<=100; i=i+1)
printf("%d, ",i);
}


The Output of the above C++ Program is given below.

This id the result of the above C program

Sunday, May 5, 2013

Refresh all of the drives of the HDD by a single click


Sometimes our computer slows down tremendously and we have to face troubles. Most often it havens for the pirated copy of windows. Or it may happens for the limitation of the hardware like low power CPU, lack of sufficient RAM etc.

Sometimes it's so boring and painful also. In this period the running program may show a message like "Not Responding". Sometimes the computer can't process a single click, the mouse pointer goes away.

If you most often face problems like these, then you can do the following...
» Upgrade your computer system (At least increase the RAM)
» Use original operating system (You may try Linux, Ubuntu in free of charge)
» Install only the necessary programs (Remove unnecessary programs if there is)
» Install an Antivirus (Microsoft Security Essential is free for Windows users)
» Free up your HDD/SSD as much you can (Delete unnecessary files like movies, songs etc.)
» Turn off windows features you don't need
» Set the recommended virtual memory

Refreshing the Drives of the Hard Disk is another effective tricks. I have given here the way to refresh all the Drives at a time by Single Click. Just follow the Steps given below and make your Computer more faster now.

 Step 01  Open a Notepad Document
We will make a .bat file to refresh all of the drives by one click only. So we need to open a Notepad File to do so. Open a Notepad File first.

 Step 02  Add the Codes to the Notepad Document
We will now add the given codes to the Notepad. You may add them typing or just copying and pasting in the Notepad Document.

"Echo off
cd/
tree
C:
tree
D:
tree
E:
tree
F:
tree"

 Step 03  Now Save the File as .bat File
Now go to Save As and  save the file as "Refresh Drive.bat". Save the Notepad File in the Desktop or anywhere you like.

 Step 04  Finally Test Your Own Made .bat File
After saving the Notepad file as "Refresh Drive.bat" you will found an icon in your Desktop anywhere you have saved. Now Double Click on the icon and Refresh your all drives very easily. If you  have more drives in your computer then you can add Drives in codes or you can also decrease the codes if you have less drives.




Friday, May 3, 2013

Printing 100-1 using Do-While Loop in c

#include<stdio.h>
void main() {
   int i=100;
   do {
      printf("%d, ",i);
      i--;
   } while(i>=1);
}

Do While Loop, C++ Program



Thursday, May 2, 2013

Printing even numbers up to 50 using do-while loop

The C program is given below is a program that will print the even numbers between 1 to 50. I have used a do-while loop to make that possible. First of all I have taken an integer type variable i where I have kept 2. Then I have started the do-while loop. I have told the compiler to print the value from the variable i and just at the next line I have told to add 2 with the existing value if i. The loop process will continue till the value of i<=50.

#include<stdio.h>
void main()   {
      int i=2;
      do {
            printf("%d, ",i);
            i=i+2;
         }
      while(i<=50);
}



C Program to Print 1-100 Using Do-While Loop

The C Program given below will print the numbers between 1 to 100. I have used Do-While Loop to print those numbers. But it is also possible with both For Loop and While Loop.

In this program a variable i is initialized with 1 using the line int i=1;. That's why the program will print 1 at the first of all during executing the 5th line printf("%d, ",i); and in the 6th line the value of i will be increased by 1.

In the condition there is written while(i<=100);. That's why the loop will continue till the value of i is 100.
#include<stdio.h>
void main(){
int i=1;
do{
printf("%d, ",i);
i++;
}while(i<=100);
}

Do-While Loop, Uses of Loop




Summation of 1 to n Numbers of Numbers

Summation of 1 to n Numbers of Numbers

#include<stdio.h>
void main()
{
int i,sum=0,num;
printf("Enter the Number: ");
scanf("%d",&num);
for(i=1; i<=num; i++)
sum=sum+i;
printf("The Summation is: %d",sum);
}

summation in C++, C++ Program, Programming

C program to add 1-10 altogether

The c program given below will add the numbers from 1 to 10 and finally the result will be displayed. In the line 6, two integer type variables i and sum are taken. But you may avoid this line, then you need to change the 9th line as for(int i=1; i<=10; i++){ and the 10th line as int sum=sum+i;

From the 9th line the for-loop has started, where the variable i is initialized by 1. There is a condition i<=10, that means the loop will continue till the value of i become 10.

Inside the for-loop there is an operation sum=sum+i;, that means the value of i will be added with the value of sum and finally the summation will be stored into the variable. This process will continue till the value of i become 10. Thus the program will add all the numbers from 1-10.

By the 13th line printf("The Sumation is: %d",sum); will display the value stored into the variable sum.

//c program to add number 1-10
#include<stdio.h>
//main function
void main(){
    //declaring integer type variables
    int i, sum=0;
    
    //for loop to add numbers 1-10
    for(i=1; i<=10; i++){
        sum=sum+i;
    }
    //displaying the result
    printf("The Sumation is: %d",sum);
}



Wednesday, May 1, 2013

C program to print 1 to 100 using while-loop

//printing 1-100 using while-loop
#include<stdio.h>
//main function
void main(){
    //initializing integer i
    int i=1;
    //while-loop to display till 100
    while(i<=100){
        printf("%d,",i);
        i++;
    }
}

C program to get the area of a circle

The c program given below will calculate the area of circle after getting the radius. We know that, area of a circle = πr2. Now, if we need to find out the area of a circle then we need to know the radius only. Because, the value of π is constant (3.1416).

That's why just after running the program, you will get a message to provide the radius of the circle. After providing the radius, soon the area of the circle will be calculated and will be displayed on the screen.

In the 6th line there I have declared two float type variables radius and area. We will use the variable radius to store the radius of the circle after getting input from keyboard. By the 9th line a message will be displayed asking to input the radius. When you will provide the input, then it will be received and stored to the variable radius by the 12th line.

By the 15th line area of the circle will be calculated and the result will be stored into the variable area. Later, by the 18th line the result will be displayed.
c program,computer programming,area of circle
//c program to get the area of a circle
#include<stdio.h>
//main function
void main(){
    //declaring float type variables
    float radius, area;
    
    //displaying message to input the radius
    printf("Enter the Radius of the Circle: ");
    
    //getting data into the float type variable
    scanf("%f",&radius);
    
    //calculation to get the area of a circle
    area=3.1416*radius*radius;
    
    //displaying the result
    printf("The Area of the Circle is: %.2f",area);
}


Converting temperature from Degree Celsius to Fahrenheit & Kelvin


The c program given below is able to convert temperature into Fahrenheit and Kelvin. When you will run the program then you will be asked to provide temperature in degree Celsius. It will be asked for the 10th line of those codes.

When you will provide the temperature then it will be store into a float type variable c by the 13th line. Later by the 16th line the temperature will be converted into Fahrenheit and will be stored into a variable f.

And soon the converted temperature will be displayed by the 19th line.

Similarly the temperature will be converted into kelvin and will be stored into the variable k by the 22nd line. Finally the temperature in kelvin will be displayed by the 25th line.
//including header file
#include<stdio.h>

//main function started
void main(){
    //declaring float type variable
    float c, f, k;

    //message to input temperature
    printf("Temperature in Degree Celsius: ");

    //storing temperature into c
    scanf("%f",&c);

    //converting to fahrenheit & storingt into f
    f=1.8*c+32;

    //displaying converted temperature
    printf("Temperature in Fahrenheit: %f",f);

    //converting temperature to kelvin & storing into k
    k=c+273;

    //displaying converted temperature
    printf("\nTemperature in Kelvin: %f",k);
}

Advertisement

C++ Program to Print 1-100 Using for loop

Uses of For Loop

#include<stdio.h>
void main()
{
int i;
for(i=1; i<=100; i++)
printf("%d, ",i);
}

for loop, 1-100 using for loop. 1 to 100 using for loop

C++ Program to Define a Grade Depending on Marks

Define Grade Depending on Marks

#include<stdio.h>
void main()
{
float num;
   printf("Enter the Number: ");
scanf("%f",&num);
if(num<0||num>100)
    printf("The Number is invalid, Try again");
else if(num>=80&&num<=100)
    printf("You've Obtained A+ Grade");
else if(num>=70&&num<80)
    printf("You've Obtained A Grade");
else if(num>=60&&num<70)
    printf("You've Obtained A");
else if(num>=50&&num<60)
    printf("You've Obtained B Grade");
else if(num>=40&&num<50)
    printf("You've Obtained C Grade");
else if(num>=33&&num<40)
    printf("You've Obtained D Grade");
else
printf("You've Obtained F Grade");
}

Define Grade Point by C Program, C++ Program

Find Out the Grade Point Depending on the Marks

Program to Find Out Grade Point

Enter your marks and get your grade point by this program.

#include<stdio.h>
void main()
{
float Marks;
printf("Plz enter your marks: ");
scanf("%f",&Marks);
if(Marks>100||Marks<0)
printf("The marks is invalid");
else if(Marks>=80&&Marks<=100)
printf("You get A+");
else if(Marks>=70&&Marks<80)
printf("You get A Grade");
else if
(Marks>=60&&Marks<70)
printf("You get A-");
else if
(Marks>=50&&Marks<60)
printf("You get B ");
else if
(Marks>=40&&Marks<50)
printf("You get C Grade");
else if
(Marks>=33&&Marks<40)
printf("You get D Grade");
else
printf("You are faild");
}




Now if you enter a number suppose this number is 50. At first this number cheeked by first 'if' because of false of first if this number cheeked by second elseif, if condition true then print grade and if false this number cheeked by next elseif, when condition true then print grade. If you enter smallest or lowset number from 33 then you get print 'You are faild'.    

In 0-100 Define Even Numbers in C++

Program For Even Number 

The C++ Program is given below is a program to define Even numbers 0-100. When you will run this program then you will get the even number up to 100.

#include<stdio.h>
void main()
{
int i;
for(i=2; i<=100; i=i+2)
printf("%d,",i);
}

Friends please see this code, in this code we use a for loop. You know we used 'for loop' for repeat any statement several time or many time. So we use for loop for print Even numbers up to 100. In for loop we declare initialization=2, Condition <=100 and we increment =2. Use this for loop we get first even number 2, second is 4  and so on.