Tuesday, 28 August 2012

c program rating counter using array

For beginners
{I am going write the c program but before you need a c compiler(software).there are a lot of compilers(software) for windows 7  like Code::Blocks,dev c++ Download dev c++ its free and install it in your computer.open  dev c++ go to file-->new-->source file.}  



#include <stdio.h>
#include<conio.h>
int main (void)
{
int ratingCounter[11], i, response,n;
printf("enter number of people\n");
scanf("%d",&n);
for ( i = 1; i <= 10; ++i )
ratingCounter[i] = 0;
printf ("Enter your rating(1 to 10)\n");
for ( i = 1; i <= n; ++i ) 
{
scanf ("%i", &response);
if ( response < 1 || response > 10 )
printf ("Bad response: %i\n", response);
else
++ratingCounter[response];
}
printf ("\n\nRating Number of Responses\n");
printf ("------ -------------------\n");
for ( i = 1; i <= 10; ++i )
printf ("%4i%12i\n", i, ratingCounter[i]);
getch();
return 0;
}

Output
enter number of people
10
Enter your rating(1 to 10)
1
2
3
2
5
6
5
8
10

Rating Number of Responses
------------- -----------------------------
     1                       1
     2                       2
     3                       1
     4                       0
     5                       2
     6                       1
     7                       0
     8                       2
     9                       0
    10                      1

For beginners
{After typing this program go to execute-->compile & run-->a window will pop-up-->give file name:(anything u like)-->save as type: c source files-->click save.}

IS IT HELPFIL? comment.

No comments:

Post a Comment