Add first ten odd numbers in C

| December 15, 2010 | 0 Comments

This article demonstrates how to add first ten odd numbers in C starting from 1. I am writing this article as I was preparing assignment of SMU MCA First Semester August 2010 MC0061. So I too faced problem for that. Well … this is solution for those students.

#include
main()
{
     int num=1;
     int total,counter;

 printf("Checking first ten odd numbers and adding them together...\n");

 while(counter<10)
 {
 if(num%2!=0)
 {
  printf("%d\n",num);
  total=total+num;
  counter++;
 }
 num++;
 }
 printf( "Total of first ten odd numbers is: %d\n", total );
}

Tags:

Category: .NET

Leave a Reply

Sex Chat Live Jasmin WP-Clear 3.0 Theme
%d bloggers like this: