@MD_ItteshamItte/

Project Euler no1

C

No description

fork
loading
Files
  • main.c
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/*//Hello guys This video is for those top programmers that want to challenge themselves in the field of programming. I did mines in C//
//Euler project no. 1//

#include <stdio.h>//Basic header files//

int main(void) // main function can only bewritten once//
{
  int i, sum=0; // declarations of variables of type int. sum is initialized to 0 for the use of sum loop involving repeating multiple of i to be added after the loop validates and returns value for i//
  for(i = 1; i<1000; i++) //For loop used to state conditions for the questions **notice the curly brackets used for the for loop and 1) the statement initializing the value of i with i = 1; using ; after to end first part of condition 2) setting range for condition 3) and the increment factor as there are 1000 numbers to consider for the next condion written in the if statement.// 
  {
    if (i%3==0 || i%5==0) //The multiples are either completely divisible by 3 or 5 so || (or) relation operator used.//
  {
    printf("i is %d\n", i); // used to print the value of i//
    sum +=i; //sum + = i; is the same as sum = sum + i; This forms an endless loop until the for statement reaches its limit of 1000.
    printf("sum is %d\n", sum); //Prints the value of sum notice the usage of %d which is the integer format specifier which will print out the final sum.
  }

  } 
  return(0);
}*/
/*#include <stdio.h>
int main (void)
{
  int i,n,k;
for (i= 1; i<=20; i++)
{
//printf("i is %d\n", i);//
if(i%2 != 0)
{
  k = printf("i is %d\n",i);
  printf("k is %d\n",k);
}
}

return(0);
}*/
/*#include <stdio.h>
int main()
{
  int i,k,sum = 0;;
  for(i=1;i<=100;i++)
  {
    printf("Enter  integer\n");
    scanf("%d",&k);
    sum +=k;
    printf("sum is %d",sum);

  }
  return(0);
}*/
//Q2//
/*#include <stdio.h>

int main(void)
{
  int i, b,n,sum=0;
  printf("
  ");
  for(i = 0; i<n; i++)
  {
    
    n = 1;
    printf("%d\n", n);

    b = i + n;
    sum = b+n;
    printf("%d\n", &b );
    printf("%d\n", sum);

  }
  return(0);
}*///not complete//
    //Q3//
/*#include <stdio.h>
int main(void)
{
  int i,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10;
  printf("Enter integer\n");
  scanf("%d", &i);
  
    if (i%2==0)
    {
    n2 = i/2;
    printf("%d\n",n2); 
    }
    if(i%3==0)
    { 
    n3 = i/3;
    printf("%d\n",n3);
    }
    if (i%4==0)
    {
    n4 = i/4;
    printf("%d\n",n4);
    }
     if (i%5==0)
    {
    n5 = i/5;
    printf("%d\n",n5);
    }
    if (i%6==0)
    {
    n6 = i/6;
    printf("%d\n",n6); 
    }
    if (i%7==0)
    {
    n7 = i/7;
    printf("%d\n",n7);
    }
      if (i%8==0)
     { 
     n8 = i/8;
    printf("%d\n",n8);
      }
      if(i%9==0)
     { 
     n9 = i/9;
    printf("%d",n9);
     }
    if (i%10==0)
    {
     n10 = i/10;
    printf("%d",n10);
    return(0);
    }*/


/*#include<stdio.h>
 
int main()
{
   int n, i = 3, count, c;
 
   printf("Enter the number of prime numbers required\n");
   scanf("%d",&n);
 
   if ( n >= 1 )
   {
      printf("First %d prime numbers are :\n",n);
      printf("2\n");
   }
 
   for ( count = 2 ; count <= n ;  )
   {
      for ( c = 2 ; c <= i - 1 ; c++ )
      {
         if ( i%c == 0 )
            break;
      }
      if ( c == i )
      {
         printf("%d\n", i);
         count++;
      }
      i++;
   }
 
   return 0;
}*/
/*#include<stdio.h>
#include<math.h>
int main()
{
int i,//b//,n,//k//,sum = 0//,sum1=0,difference//;
for (i= 1; i<100; i++)

n = pow(i,2);
sum+=n;
printf("sum is %d\n", sum);

//for (i= 1; i<100; i++)
{
sum1+=i;
printf("sum1 is %d\n", sum1);
b = pow(sum1,2);
printf("b is %d\n", b);
}
difference = b -sum;
printf("difference is %d\n", difference);//
return(0);
}*/

/*#include <stdio.h>
#include <math.h>
int main(void)
{
  int i,k;
  k = pow(2, 10);
  printf(" %d",k);
}*/
//no.4//
/*#include <stdio.h>
#include <math.h>
int main(void)
{
  int i,j,k;
  for(i = 100;i<=999;i++)
  {
      
    for(j =100;j<=999;j++)
  
  {
    k = i*j;
    printf("%d\n",k);
  }
    
    
  
}
return(0);
}*/

/*#include <stdio.h>
 
int main()
{
   int n, reverse = 0, t;
 
   printf("Enter a number to check if it is a palindrome or not\n");
   scanf("%d", &n);
 
   t = n;
 
   while (t != 0)
   {
      reverse = reverse * 10;
      reverse = reverse + t%10;
      t = t/10;
   }
 
   if (n == reverse)
      printf("%d is a palindrome number.\n", n);
   else
      printf("%d isn't a palindrome number.\n", n);
 
   return 0;
}
*/
//Q19//
/*
#include<stdio.h>
int main (void)
{
  int m,m31,m30,mlp,mnlp,ttldy,d;
  m31 = 7*31*100;
  m30 = 4*30*100;
  mlp = 25*29;
  mnlp = 75*28;
  printf("%d\n%d\n%d\n%d\n1",m31, m30,mlp,mnlp);
  for(m = 1901; m<=2000; m= m+1)
  if(m%4==0)
  {
    printf("%d\n", m);
  }
  else if(m/10 && m%400 ==0)
  {
    printf("%d",m);
  }
  ttldy = m31+m30+mlp+mnlp;
  printf("%d",ttldy);
  for(d =6;d<=36525;d +=7)
  {
    printf("%d\n",d);
  }


return(0);
}*/
//Q20//
#include <stdio.h>
#include <math.h> 
int main (void)
{
  double i, mult=1;
  int  rem,sum=0;
  for(i = 100;i>=1;i--)
  {
    mult = mult*i;
    printf("mult is %lf\n",mult);
  }
  while(mult>0)
   
  rem = fmod(mult,10);
  sum = sum+rem;
  mult = mult/10;
  printf("sum is %d\n",sum);
  

return(0);
}

//Question no.16//
/*#include <stdio.h>
#include <math.h>

int main(void)
{

  
    double k,j,l,m;
    l= pow(2,33);
    printf("%lf\n",l);
    k = pow(8589934592, 3);
    printf("%lf\n",k);
    j=2*k;
    printf("%lf\n",j);
    m = pow(j,10);
    printf("%lf",m);
      return(0);
      }*/
/*#include <stdio.h>
#include <math.h>

//int main(void)// t
int main()
{
  double k,j,l, m;

  int rem,sum=0;
    l= pow(2,33);
    printf("%lf\n",l);
    k = pow(8589934592, 3);
    printf("%lf\n",k);
    j=2*k;
    printf("%lf\n",j);
    m = pow(j,10);
    printf("%lf\n",m);
    //code to find the digits of a sequence of numbers//
  
  while(m>0)
  {
  
    rem = fmod( m,10);
    sum = sum + rem;
    m = m/10;
  }
printf("sum is %d", sum);

return(0);
}*/

/*
#include <stdio.h>
#include <math.h>
#include <conio.h>
//int main(void)//
void main()
{
      int num,rem,sum;
    clrscr();
    printf("Enter an integer");
    scanf("%d", &num);
    while(num)
    {
      rem = num%10;
      sum = sum + rem;
      num = num/10;
    }
     printf("sum is %d",sum);
    

    //https://docs.google.com/document/d/1Kl9w1jxx8dT_QFqY2e_eKUvr7ISY_B99c9-uaV373cg/edit#heading=h.qdupdlc8wl//
    */