Saturday, November 5, 2011

Generate 100 Random numbers and print their average

Write a Program which Generates One Hundred Random Integers in the Range of 1 To
100, store them in an array and then prints the average. write three versions of the
program using Different Loop Constructs (e.g for, while and do. while).


Using For Loop

#include
#include
#include
void main()
{
int a[100],i;
float sum=0,avg;
clrscr();
randomize();
for(i=0;i<100;i++)
{
a[i]=random(100);
sum=sum+a[i];
}
avg=sum/100;
for(i=0;i<100;i++)
printf("%d\t",a[i]);
printf("\naverage=%f",avg);
getch();
}



Using While Loop


#include
#include
#include
void main()
{
int a[100],i;
float sum=0,avg;
clrscr();
randomize();
while(i<100)
{
a[i]=random(100);
sum=sum+a[i];
i++;
}
i=0;
avg=sum/100;
while(i<100)
{
printf("%d\t",a[i]);
i++;
}
printf("\naverage=%f",avg);
getch();
}


Using do-While Loop


#include
#include
#include
void main()
{
int a[100],i;
float sum=0,avg;
clrscr();
randomize();
do
{
a[i]=random(100);
sum=sum+a[i];
printf("%d\t",a[i]);
i++;
}
avg=sum/100;
printf("\naverage=%f",avg);
getch();
}
Read full history - Generate 100 Random numbers and print their average

Free Download Turbo C for Windows 7 64 bit,32 bit And Windows Vista

Windows vista and windows 7 are both popular operating system, but when we compare this operating system with windows XP some of the basic operations/software which we use in XP won’t support in Vista or windows 7 operating system. For example command prompt in vista and windows 7 won’t show the full screen, and another major drawback is Turbo C software won’t support in both windows vista as well as windows 7 OS. So we cannot able to work C/C++ in our newer operating system. So here is a solution for that, with the help of  “Emulated Turbo C++ IDE 3.0” software we can work Turbo C fine in windows vista, windows 7 32 and 64 bit PC. This software is like a C for win7 and C for Vista.


We can using turbo c software for window 7 64 bit in other way also i.e by using DOSBox software and Turbo C software. In this way we have to configure manually to work turbo c for win7. But with Emulated Turbo C++ IDE 3.0 software we don’t need to configure anything and it is one click installer software. To work C in Win7/vista 64 bit or 32 bit only you need to install Emulated Turbo C++ IDE 3.0 software and after installing that software you can successfully run turbo c compiler in windows 7 64 bit pc.
I have tried turbo c in win7 by manual method, and with that method what I feel is installing Emulated Turbo C++ IDE 3.0 (C for win 7) software is good when compared with DOSBox installation method. Because in DOSBox method some of the shortcut keys of turbo c software won’t work (perform different task) and number pad (keyboard) won’t work properly (ex: to turn on numpad we have to press NumLk button twice or thrice to turn on) and configuring turbo c software for windows 7 64 bit pc is some what difficulty and time-consuming process.
So those who are looking for installing or working with turbo c in windows 7, I recommend you to go for Emulated Turbo C++ IDE 3.0 by mohit saxena instead of DOSBox method. According the developer he said turbo c supports full screen in windows vista  and windows 7 O.S but I don’t think it fully support full screen. In both the DOSBox method and Emulated Turbo C++ IDE 3.0 method turbo c opens in same screen size.

DOWNlOAD from here .



Read full history - Free Download Turbo C for Windows 7 64 bit,32 bit And Windows Vista

About Me