SlideShare a Scribd company logo
1 of 50
Download to read offline
Rajshahi University of Engineering and Technology
“Heavens Light Is Our Guide”
Department of Electrical & Computer Engineering (ECE)
Assignment
Course No: ECE-1103.
Course Title: Computer Programming.
Assignment Name: Solving 50 programming problems.
Submitted To: Submitted By:
Sagor Chandro Bakchy.
Assistant Professor,
Department of Electrical & Computer
Engineering, RUET
MD. Samiul Haque Biswas.
Roll: 2010052.
Session: 2020-21
BeeCrowd ID link: https://www.beecrowd.com.br/judge/en/profile/692469
Problem No: 1051
Solution Code:
#include <stdio.h>
int main()
{
float salary;
scanf("%f", &salary);
if (salary <= 2000)
{
printf("Isenton");
}
else if (salary <= 3000)
{
printf("R$ %.2fn", (salary-2000)*0.08);
}
else if (salary <= 4500)
{
printf("R$ %.2fn", 80+((salary-3000)*0.18));
}
else if(salary>4500)
{
printf("R$ %.2fn", 350+((salary-4500)*0.28));
}
return 0;
}
Problem No: 1052
Solution Code:
#include <stdio.h>
int main()
{
int a;
scanf("%d", &a);
switch (a)
{
case 1:
printf("Januaryn");
break;
case 2:
printf("Februaryn");
break;
case 3:
printf("Marchn");
break;
case 4:
printf("Apriln");
break;
case 5:
printf("Mayn");
break;
case 6:
printf("Junen");
break;
case 7:
printf("Julyn");
break;
case 8:
printf("Augustn");
break;
case 9:
printf("Septembern");
break;
case 10:
printf("Octobern");
break;
case 11:
printf("Novembern");
break;
case 12:
printf("Decembern");
break;
}
return 0;
}
Problem NO: 1059
Solution Code:
#include <stdio.h>
int main()
{
for (int i = 2; i < 101; i = i + 2)
{
printf("%dn", i);
}
return 0;
}
Problem No: 1061
Solution Code:
#include <stdio.h>
int main()
{
int h, hh, hr, m, mm, d, dm, s, ss;
scanf("Dia %d", &d);
scanf("%d : %d : %dn", &h, &m, &s);
scanf("Dia %d", &dm);
scanf("%d : %d : %d", &hh, &mm, &ss);
s = ss - s;
m = mm - m;
h = hh - h;
d = dm - d;
if (s < 0)
{
s += 60;
m--;
}
if (m < 0)
{
m += 60;
h--;
}
if (h < 0)
{
h += 24;
d--;
}
printf("%d dia(s)n", d);
printf("%d hora(s)n", h);
printf("%d minuto(s)n", m);
printf("%d segundo(s)n", s);
return 0;
}
Problem No: 1060
Solution Code:
#include <stdio.h>
int main()
{
int t = 6,s=0;
while (t--)
{
float a;
scanf("%f", &a);
if (a > 0)
s++;
}
printf("%d valores positivosn", s);
return 0;
}
Problem No: 1061
Solution Code:
#include <stdio.h>
int main()
{
int h, hh, hr, m, mm, d, dm, s, ss;
scanf("Dia %d", &d);
scanf("%d : %d : %dn", &h, &m, &s);
scanf("Dia %d", &dm);
scanf("%d : %d : %d", &hh, &mm, &ss);
s = ss - s;
m = mm - m;
h = hh - h;
d = dm - d;
if (s < 0)
{
s += 60;
m--;
}
if (m < 0)
{
m += 60;
h--;
}
if (h < 0)
{
h += 24;
d--;
}
printf("%d dia(s)n", d);
printf("%d hora(s)n", h);
printf("%d minuto(s)n", m);
printf("%d segundo(s)n", s);
return 0;
}
Problem No: 1064
Solution Code:
#include <stdio.h>
int main()
{
int t = 6,s=0; //SamiulHaque
float x=0;
while (t--)
{
float a;
scanf("%f", &a);
if (a > 0)
{
s++;
x = x + a;
}
}
printf("%d valores positivosn", s);
printf("%.1fn", float(x / s));
return 0;
}
Problem No: 1065
Solution Code:
#include <stdio.h>
int main()
{
int t = 5, s = 0;
while (t--)
{
int a;
scanf("%d", &a);
if (a % 2 == 0)
s++;
}
printf("%d valores paresn", s);
return 0;
}
Problem No: 1066
Solution Code:
#include <stdio.h>
int main()
{
int t = 5, e = 0, o = 0, p = 0, n = 0;
while (t--)
{
int a;
scanf("%d", &a);
if (a % 2 == 0 || (a*(-1))%2==0) //SamiulHaque
{
e++;
}
else
{
o++;
}
if (a > 0)
{
p++;
}
else if(a<0)
{
n++;
}
}
printf("%d valor(es) par(es)n", e);
printf("%d valor(es) impar(es)n", o);
printf("%d valor(es) positivo(s)n", p);
printf("%d valor(es) negativo(s)n", n);
return 0;
}
Problem No: 1067
Solution Code:
#include<stdio.h>
int main()
{
int t;
scanf("%d", &t);
for (int i = 1; i < t + 1; i=i+2)
{
printf("%dn", i);
}
return 0;
}
Problem No: 1070
Solution Code:
#include <stdio.h>
int main()
{
int x;
scanf("%d", &x);
if (x % 2 == 0)
{
for (int i = x+1; i < x + 12; i = i + 2)
{
printf("%dn", i);
}
}
else if (x % 2 != 0)
{
for (int i = x; i < x + 11; i = i + 2)
{
printf("%dn", i);
}
}
return 0;}
Problem No: 1071
Solution Code:
#include <stdio.h>
int main()
{
int x, y, s = 0;
scanf("%d %d", &x, &y);
if (x > y)
{
for (int i = y+1; i < x; i++)
{
if (i % 2 != 0)
s = s + i;
}
printf("%dn", s);
}
else if (x < y)
{
for (int i = x+1; i < y; i = i++)
{
if (i % 2 != 0)
s = s + i;
}
printf("%dn", s);
}
else
{
printf("0n");
}
}
Problem No: 1072
Solution Code:
#include <stdio.h>
int main()
{
int n,c=0,d=0;
scanf("%d",&n);
for (int i = 0; i < n; i++)
{
int x;
scanf("%d", &x);
if (x >= 10 && x <= 20)
{
c++;
}
else
{
d++; } }
printf("%d inn", c);
printf("%d outn", d);
return 0;
}
Problem No: 1073
Solution Code:
#include <stdio.h>
int main()
{
long long int n;
scanf("%lld", &n);
if (n % 2 == 0)
{
for (long long int i = 2; i < n + 1; i=i+2)
{
printf("%lld^2 = %lldn",i,i*i);
}
}
else
{
for(long long int i=2; i<n; i=i+2)
{
printf("%lld^2 = %lldn",i,i*i);
}
}
}
Problem No: 1074
Solution Code:
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
while (n--)
{
int x;
scanf("%d", &x);
if (x == 0)
{
printf("NULLn");
}
else if (x % 2 == 0 && x > 0)
{
printf("EVEN POSITIVEn");
}
else if (x % 2 == 0 && x < 0)
{
printf("EVEN NEGATIVEn");
}
else if (x % 2 != 0 && x < 0)
{
printf("ODD NEGATIVEn");
}
else if (x % 2 != 0 && x > 0)
{
printf("ODD POSITIVEn");
}
}
return 0;
}
Problem No: 1075
Solution Code:
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i <= 10000; i++)
{
if (i % n == 2)
printf("%dn",i);
}
return 0;
}
Problem No: 1078
Solution Code:
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i <= 10; i++)
{
printf("%d x %d = %dn", i, n, i * n);
}
return 0;
}
Problem No: 1079
Solution Code:
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
while (n--)
{
float a, b, c;
scanf("%f %f %f", &a, &b, &c);
printf("%.1fn",(a*2+b*3+c*5)/10);
}
return 0;}
Problem No: 1080
Solution Code:
#include <stdio.h>
int main()
{
int highest = -999;
int a[100];
for (int i = 0; i < 100; i++)
{
scanf("%d", &a[i]);
}
for (int i = 0; i < 100; i++)
{
if (highest < a[i])
highest = a[i];
}
printf("%dn", highest);
for (int i = 0; i < 100; i++)
{
if (a[i] == highest)
printf("%dn", i + 1);
}
}
Problem No: 1094
Solution Code:
#include <stdio.h>
int main()
{
int n, p = 0, q = 0, r = 0, t;
float e, f, g;
scanf("%d", &n);
while (n--)
{
int x;
char a;
scanf("%d %c", &x, &a);
if (a == 'C')
{
p = p + x;
}
else if (a == 'R')
{
q = q + x;
}
else if (a == 'S')
{
r = r + x;
}
}
t = p + q + r;
e = float((p * 100.00) / t);
f = float((q * 100.00) / t);
g = float((r * 100.00) / t);
printf("Total: %d cobaiasn", t);
printf("Total de coelhos: %dn", p);
printf("Total de ratos: %dn", q);
printf("Total de sapos: %dn", r);
printf("Percentual de coelhos: %.2f %%n", e);
printf("Percentual de ratos: %.2f %%n", f);
printf("Percentual de sapos: %.2f %%n", g);
return 0;
}
Problem No: 1095
Solution Code:
#include <stdio.h>
int main()
{
int sum = 60;
for (int i = 1; i <= 37; i = i+3)
{
printf("I=%d J=%dn", i, sum);
sum = sum - 5;
}
return 0;
}
Problem No: 1096
Solution Code:
#include <stdio.h>
int main()
{
for (int i = 1; i <= 9; i = i + 2)
{
printf("I=%d J=7n", i);
printf("I=%d J=6n", i);
printf("I=%d J=5n", i);
}
return 0;
}
Problem No: 1097
Solution Code:
#include <stdio.h>
int main()
{
int a = 7, b = 6, c = 5;
for (int i = 1; i <= 9; i = i + 2)
{
printf("I=%d J=%dn", i, a);
printf("I=%d J=%dn", i, b);
printf("I=%d J=%dn", i, c);
a = a + 2;
b = b + 2;
c = c + 2;
}
return 0;
}
Problem No: 1098
Solution Code:
#include <stdio.h>
int main()
{
float i, j, a = 1.2, b = 2.2, c = 3.2;
printf("I=0 J=1n");
printf("I=0 J=2n");
printf("I=0 J=3n");
for (i = 0.2; i < 1; i = i + 0.2)
{
printf("I=%0.1f J=%0.1fn", i, a);//SamiulHaque
printf("I=%0.1f J=%0.1fn", i, b);
printf("I=%0.1f J=%0.1fn", i, c);
a = a + 0.2;
b = b + 0.2;
c = c + 0.2;
}
printf("I=1 J=2n");
printf("I=1 J=3n");
printf("I=1 J=4n");
a=2.2,b=3.2,c=4.2;
for (i = 1.2; i < 2; i = i + 0.2)
{
printf("I=%0.1f J=%0.1fn", i, a);//SamiulHaque
printf("I=%0.1f J=%0.1fn", i, b);
printf("I=%0.1f J=%0.1fn", i, c);
a = a + 0.2;
b = b + 0.2;
c = c + 0.2;
}
printf("I=2 J=3n");
printf("I=2 J=4n");
printf("I=2 J=5n");
return 0;
}
Problem No: 1099
Solution Code:
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
while (n--)
{
int x, y, sum = 0;
scanf("%d %d", &x, &y);
if (x == y)
{
printf("0n");
}
if (x > y && y % 2 == 0)
{
for (int i = y + 1; i < x; i = i + 2)
{
sum = sum + i;
}
printf("%dn", sum);
}
else if (x > y && y % 2 != 0)
{
for (int i = y + 2; i < x; i = i + 2)
{
sum = sum + i;
}
printf("%dn", sum);
}
else if (y > x && x % 2 == 0)
{
for (int i = x + 1; i < y; i = i + 2)
{
sum = sum + i;
}
printf("%dn", sum);
}
else if(y>x && x%2!=0)
{
for (int i = x + 2; i < y; i = i + 2)
{
sum = sum + i;
}
printf("%dn", sum);
}
}
return 0;
}
Problem No: 1101
Solution Code:
#include <stdio.h>
int main()
{
int m, n;
for (int i = 0; i >= 0; i++)
{
int sum=0;
scanf("%d %d", &m, &n);
if (m > 0 && n > 0)
{
if (m >= n)
{
for (int j = n; j < m + 1; j++)
{
printf("%d ", j);
sum = sum + j;
}
printf("Sum=%dn", sum);
}
else
{
for (int j = m; j < n + 1; j++)
{
printf("%d ", j);
sum = sum + j;
}
printf("Sum=%dn", sum);
}
}
else
{
break;
}
}
return 0;
}
Problem No: 1113
Solution Code:
#include <stdio.h>
int main()
{
for (int i = 0; i >= 0; i++)
{
int x, y, r;
scanf("%d %d", &x, &y);
r = x - y;
if (r == 0)
{
break;
}
else if (r > 0)
{
printf("Decrescenten");
}
else if (r < 0)
{
printf("Crescenten");
}
}
return 0;
}
Problem No: 1114
Solution Code:
#include <stdio.h>
int main()
{
for (int i = 0; i >= 0; i++)
{
int n;
scanf("%d", &n);
if (n == 2002)
{
printf("Acesso Permitidon");
break;
}
else
{
printf("Senha Invalidan");
}
}
return 0;
}
Problem No: 1115
Solution Code:
#include <stdio.h>
int main()
{
for (int i = 0; i >= 0; i++)
{
int x, y;
scanf("%d %d", &x, &y);
if (x == 0 || y == 0)
{
break;
}
else if (x > 0 && y > 0)
{
printf("primeiron");
}
else if (x > 0 && y < 0)
{
printf("quarton");
}
else if (x < 0 && y < 0)
{
printf("terceiron");
}
else if (x < 0 && y > 0)
{
printf("segundon");
}
}
return 0;
}
Problem No: 1116
Solution Code:
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
while (n--)
{
float x, y;
scanf("%f %f", &x, &y);
if (y == 0)
{
printf("divisao impossiveln");
}
else
{
printf("%.1fn", (x / y));
}
}
return 0;
}
Problem No: 1117
Solution Code:
#include <stdio.h>
int main()
{
float x, sum;
int j = 1;
while (j < 3)
{
scanf("%f", &x);
if (x >= 0.0 && x <= 10.0)
{
sum = sum + x;
j++;
continue;
}
else
{
printf("nota invalidan");
continue;
}
}
printf("media = %.2fn", sum / 2.0);
return 0;
}
Problem No: 1118
Solution Code:
#include <stdio.h>
int main()
{
int x = 1, j = 0;
float s[2], a, avg;
while (x != 2)
{
if (x == 1)
{
while (j <= 1)
{
scanf("%f", &a);
if (a >= 0.0 && a <= 10.0)
{
s[j] = a;//SamiulHaque
j++;
}
else
{
printf("nota invalidan");
}
}
avg = (s[0] + s[1]) / 2.0;
printf("media = %.2fn", avg);
}
printf("novo calculo (1-sim 2-nao)n");
scanf("%d", &x);
j = 0;
continue;
}
return 0;
}
Problem No: 1132
Solution Code:
#include <stdio.h>
int main()
{
int x, y, add = 0;
scanf("%d %d", &x, &y);
if (x == y)
{
printf("0");
}
else if (x > y)
{
for (int i = y; i <=x; i++)
{
if (i % 13 != 0)
{
add = add + i;
}
}
printf("%dn", add);
}
else if (x < y)
{
for (int i = x; i <=y; i++)
{
if (i % 13 != 0)
{
add = add + i;
}
}
printf("%dn", add);
}
return 0;
}
Problem No: 1133
Solution Code:
#include <stdio.h>
int main()
{
int x, y, a = 0, b = 0;
scanf("%d %d", &x, &y);
if (x > y)
{
for (int i = y + 1; i < x; i++)
{
if (i % 5 == 2 || i % 5 == 3)
{
printf("%dn", i);
}
}
}
else if (x < y)
{
for (int i = x + 1; i < y; i++)
{
if (i % 5 == 2 || i % 5 == 3)
{
printf("%dn", i);
}
}
}
return 0;}
Problem No: 1134
Solution Code:
#include <stdio.h>
int main()
{
int a = 0, b = 0, c = 0;
for (int i = 1; i > 0; i++)
{
int n;
scanf("%d", &n);
if(n==1)
{
a++;
}
else if(n==2)
{
b++;
}
else if(n==3)
{
c++;
}
else if(n==4)
{
break;
}
else
{
continue;
}
}
printf("MUITO OBRIGADOn");
printf("Alcool: %dn", a);
printf("Gasolina: %dn", b);
printf("Diesel: %dn", c);
return 0;
}
Problem No: 1142
Solution Code:
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
int a = 1, b = 2, c = 3;
while (n--)
{
printf("%d ", a);
printf("%d ", b);
printf("%d ", c);
printf("PUMn");
a = a + 4;
b = b + 4;
c = c + 4;
}
return 0;
}
Problem No: 1143
Solution Code:
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
printf("%d %d %dn", i, i * i, i * i * i);
}
return 0;
}
Problem No:1144
Solution Code:
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
printf("%d %d %dn", i, i * i, i * i * i);
printf("%d %d %dn", i, (i * i) + 1, (i * i * i) + 1);
}
return 0;
}
Problem No: 1145
Solution Code:
#include <stdio.h>
int main()
{
int x, y, c = 0;
scanf("%d %d", &x, &y);
for (int i = 1; i <= y; i++)
{
if (i % x != 0)
{
printf("%d ", i);//SamiulHaque
}
else if (i % x == 0)
{
printf("%dn",i);
}
}
return 0;
}
Problem No: 1146
Solution Code:
#include <stdio.h>
int main()
{
int x;
while (x != 0)
{
scanf("%d", &x);
for (int i = 1; i <= x; i++)
{
if (i % x != 0)
{
printf("%d ", i);//SamiulHaque
}
else if (i % x == 0)
{
printf("%dn", i);
}
}
}
return 0;
}
Problem No:1149
Solution Code:
#include <stdio.h>
int main()
{
int n, a, sum = 0;
scanf("%d ", &a);
for (int i = 0; i >= 0; i++)
{
scanf("%d", &n);
if (n > 0)
{
for (int i = a; i < a + n; i++)
{
sum = sum + i;
}
printf("%dn", sum);
break;
}
else
{
continue;
}
}
return 0;
}
Problem No: 1150
Solution Code:
#include <stdio.h>
int main()
{
int x, z, sum = 0, c=0;
scanf("%d", &x);
for (int i = 0; i >= 0; i++)
{
scanf("%d", &z);
if (z <= x)
{
continue;
}
else
{
break;
}
}
for (int i = 0; i >= 0; i++)
{
sum = x + i + sum;
c++;
if (sum >= z)
{
break;
}
}
printf("%dn", c);
return 0;
}
Problem No: 1151
Solution Code:
#include <stdio.h>
int main()
{
int n, a = 0, b = 1, c;
scanf("%d", &n);
if (n == 1)
{
printf("%n", a);
}
else if (n == 2)
{
printf("%d %dn", a, b);
}
else
{
printf("%d %d", a, b);
for (int i = 2; i < n; ++i)
{
c = a + b;
printf(" %d", c);
a = b;
b = c;
}
printf("n");
}
return 0;
}
Problem No: 1153
Solution Code:
#include <stdio.h>
int main()
{
int n, fact = 1;
scanf("%d", &n);
if (n <= 1)
{
printf("1n");
}
else
{
for (int i = 1; i <= n; i++)
{
fact = fact * i;
}
printf("%dn", fact);
}
return 0;
}
Problem No: 1154
Solution Code:
#include <stdio.h>
int main()
{
float sum = 0, a = 0;
for (int i = 0; i >= 0; i++)
{
int x;
scanf("%d", &x);
if (x < 0)
{
break;
}
else if (x >= 0)
{
sum = sum + x;
a++;
}
}
printf("%.2fn", float(sum / a));
return 0;
}
Problem No: 1155
Solution Code:
#include <stdio.h>
int main()
{
float sum = 0;
for (float i = 1; i <= 100; i++)
{
sum = sum + (1 / i);
}
printf("%.2fn", sum);
return 0;
}
Problem No: 1156
Solution Code:
#include <stdio.h>
#include <math.h>
int main()
{
float sum = 0;
for (float i = 1, j = 0; i <= 39, j <= 20; i = i + 2, j++)
{
sum = sum + (i / pow(2, j));
}
printf("%.2fn", sum);
return 0;
}
Problem No: 1157
Solution Code:
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
if (n % i == 0)
{
printf("%dn", i);
}
}
return 0;
}
Problem No: 1158
Solution Code:
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
while (n--)
{
int x, y, sum = 0;
scanf("%d %d", &x, &y);
if (x % 2 == 0)
{
for (int i = x; i < x + 2 * y; i++)
{
if (i % 2 != 0)
{
sum = sum + i;
}
}
printf("%dn", sum);
}
else if (x % 2 != 0)
{
for (int i = x; i < x + 2 * y; i++)
{
if (i % 2 != 0)
{
sum = sum + i;
}
}
printf("%dn", sum);
}
}
return 0;
}
Problem No: 1159
Solution Code:
#include <stdio.h>
int main()
{
for (int i = 0; i >= 0; i++)
{
int x, sum = 0;
scanf("%d", &x);
if (x == 0)
{
break;
}
else
{
for (int i = x; i < x + 10; i++)
{
if (i % 2 == 0)
{
sum = sum + i;
}
else
{
continue;
}
}
printf("%dn", sum);
}
}
return 0;
}
Problem No: 1160
Solution Code:
#include <stdio.h>
int main()
{
int t, pa, pb, c;
double ga, gb, p, q;
scanf("%d", &t);
while (t--)
{
c = 0;
scanf("%d %d %lf %lf", &pa, &pb, &ga, &gb);
p = ga / 100;
q = gb / 100;
while (pa <= pb)
{
pa = pa + (pa * p);//SamiulHaque
pb = pb + (pb * q);
c++;
if (c > 100)
{
printf("Mais de 1 seculo.n");
break;
}
}
if (c <= 100)
{
printf("%d anos.n", c);
}
}
return 0;}
Submission Record:
RUET ECE Assignment - Solving 50 Programming Problems
RUET ECE Assignment - Solving 50 Programming Problems

More Related Content

Similar to RUET ECE Assignment - Solving 50 Programming Problems

Similar to RUET ECE Assignment - Solving 50 Programming Problems (20)

programs
programsprograms
programs
 
Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Lab Question
Lab QuestionLab Question
Lab Question
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
C programming codes for the class assignment
C programming codes for the class assignmentC programming codes for the class assignment
C programming codes for the class assignment
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
Include
IncludeInclude
Include
 
C Programming
C ProgrammingC Programming
C Programming
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdf
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docx
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdf
 
Pnno
PnnoPnno
Pnno
 
C file
C fileC file
C file
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using c
 

Recently uploaded

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Recently uploaded (20)

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

RUET ECE Assignment - Solving 50 Programming Problems

  • 1. Rajshahi University of Engineering and Technology “Heavens Light Is Our Guide” Department of Electrical & Computer Engineering (ECE) Assignment Course No: ECE-1103. Course Title: Computer Programming. Assignment Name: Solving 50 programming problems. Submitted To: Submitted By: Sagor Chandro Bakchy. Assistant Professor, Department of Electrical & Computer Engineering, RUET MD. Samiul Haque Biswas. Roll: 2010052. Session: 2020-21
  • 2. BeeCrowd ID link: https://www.beecrowd.com.br/judge/en/profile/692469 Problem No: 1051 Solution Code: #include <stdio.h> int main() { float salary; scanf("%f", &salary); if (salary <= 2000) { printf("Isenton"); } else if (salary <= 3000) { printf("R$ %.2fn", (salary-2000)*0.08); } else if (salary <= 4500) { printf("R$ %.2fn", 80+((salary-3000)*0.18)); } else if(salary>4500) { printf("R$ %.2fn", 350+((salary-4500)*0.28)); } return 0; }
  • 3. Problem No: 1052 Solution Code: #include <stdio.h> int main() { int a; scanf("%d", &a); switch (a) { case 1: printf("Januaryn"); break; case 2: printf("Februaryn"); break; case 3: printf("Marchn"); break; case 4: printf("Apriln"); break; case 5: printf("Mayn"); break; case 6: printf("Junen"); break; case 7: printf("Julyn");
  • 4. break; case 8: printf("Augustn"); break; case 9: printf("Septembern"); break; case 10: printf("Octobern"); break; case 11: printf("Novembern"); break; case 12: printf("Decembern"); break; } return 0; } Problem NO: 1059 Solution Code: #include <stdio.h> int main() { for (int i = 2; i < 101; i = i + 2) { printf("%dn", i); } return 0;
  • 5. } Problem No: 1061 Solution Code: #include <stdio.h> int main() { int h, hh, hr, m, mm, d, dm, s, ss; scanf("Dia %d", &d); scanf("%d : %d : %dn", &h, &m, &s); scanf("Dia %d", &dm); scanf("%d : %d : %d", &hh, &mm, &ss); s = ss - s; m = mm - m; h = hh - h; d = dm - d; if (s < 0) { s += 60; m--; } if (m < 0) { m += 60; h--; } if (h < 0) { h += 24; d--;
  • 6. } printf("%d dia(s)n", d); printf("%d hora(s)n", h); printf("%d minuto(s)n", m); printf("%d segundo(s)n", s); return 0; } Problem No: 1060 Solution Code: #include <stdio.h> int main() { int t = 6,s=0; while (t--) { float a; scanf("%f", &a); if (a > 0) s++; } printf("%d valores positivosn", s); return 0; } Problem No: 1061 Solution Code: #include <stdio.h> int main() {
  • 7. int h, hh, hr, m, mm, d, dm, s, ss; scanf("Dia %d", &d); scanf("%d : %d : %dn", &h, &m, &s); scanf("Dia %d", &dm); scanf("%d : %d : %d", &hh, &mm, &ss); s = ss - s; m = mm - m; h = hh - h; d = dm - d; if (s < 0) { s += 60; m--; } if (m < 0) { m += 60; h--; } if (h < 0) { h += 24; d--; }
  • 8. printf("%d dia(s)n", d); printf("%d hora(s)n", h); printf("%d minuto(s)n", m); printf("%d segundo(s)n", s); return 0; } Problem No: 1064 Solution Code: #include <stdio.h> int main() { int t = 6,s=0; //SamiulHaque float x=0; while (t--) { float a; scanf("%f", &a); if (a > 0) { s++; x = x + a; } } printf("%d valores positivosn", s); printf("%.1fn", float(x / s)); return 0; }
  • 9. Problem No: 1065 Solution Code: #include <stdio.h> int main() { int t = 5, s = 0; while (t--) { int a; scanf("%d", &a); if (a % 2 == 0) s++; } printf("%d valores paresn", s); return 0; } Problem No: 1066 Solution Code: #include <stdio.h> int main() { int t = 5, e = 0, o = 0, p = 0, n = 0; while (t--) { int a; scanf("%d", &a); if (a % 2 == 0 || (a*(-1))%2==0) //SamiulHaque {
  • 10. e++; } else { o++; } if (a > 0) { p++; } else if(a<0) { n++; } } printf("%d valor(es) par(es)n", e); printf("%d valor(es) impar(es)n", o); printf("%d valor(es) positivo(s)n", p); printf("%d valor(es) negativo(s)n", n); return 0; } Problem No: 1067 Solution Code: #include<stdio.h> int main() { int t;
  • 11. scanf("%d", &t); for (int i = 1; i < t + 1; i=i+2) { printf("%dn", i); } return 0; } Problem No: 1070 Solution Code: #include <stdio.h> int main() { int x; scanf("%d", &x); if (x % 2 == 0) { for (int i = x+1; i < x + 12; i = i + 2) { printf("%dn", i); } } else if (x % 2 != 0) { for (int i = x; i < x + 11; i = i + 2) { printf("%dn", i); } } return 0;}
  • 12. Problem No: 1071 Solution Code: #include <stdio.h> int main() { int x, y, s = 0; scanf("%d %d", &x, &y); if (x > y) { for (int i = y+1; i < x; i++) { if (i % 2 != 0) s = s + i; } printf("%dn", s); } else if (x < y) { for (int i = x+1; i < y; i = i++) { if (i % 2 != 0) s = s + i; } printf("%dn", s); } else { printf("0n"); }
  • 13. } Problem No: 1072 Solution Code: #include <stdio.h> int main() { int n,c=0,d=0; scanf("%d",&n); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); if (x >= 10 && x <= 20) { c++; } else { d++; } } printf("%d inn", c); printf("%d outn", d); return 0; } Problem No: 1073 Solution Code: #include <stdio.h> int main()
  • 14. { long long int n; scanf("%lld", &n); if (n % 2 == 0) { for (long long int i = 2; i < n + 1; i=i+2) { printf("%lld^2 = %lldn",i,i*i); } } else { for(long long int i=2; i<n; i=i+2) { printf("%lld^2 = %lldn",i,i*i); } } } Problem No: 1074 Solution Code: #include <stdio.h> int main() { int n; scanf("%d", &n); while (n--) { int x;
  • 15. scanf("%d", &x); if (x == 0) { printf("NULLn"); } else if (x % 2 == 0 && x > 0) { printf("EVEN POSITIVEn"); } else if (x % 2 == 0 && x < 0) { printf("EVEN NEGATIVEn"); } else if (x % 2 != 0 && x < 0) { printf("ODD NEGATIVEn"); } else if (x % 2 != 0 && x > 0) { printf("ODD POSITIVEn"); } } return 0; } Problem No: 1075 Solution Code: #include <stdio.h> int main() {
  • 16. int n; scanf("%d", &n); for (int i = 1; i <= 10000; i++) { if (i % n == 2) printf("%dn",i); } return 0; } Problem No: 1078 Solution Code: #include <stdio.h> int main() { int n; scanf("%d", &n); for (int i = 1; i <= 10; i++) { printf("%d x %d = %dn", i, n, i * n); } return 0; } Problem No: 1079 Solution Code: #include <stdio.h> int main() { int n;
  • 17. scanf("%d", &n); while (n--) { float a, b, c; scanf("%f %f %f", &a, &b, &c); printf("%.1fn",(a*2+b*3+c*5)/10); } return 0;} Problem No: 1080 Solution Code: #include <stdio.h> int main() { int highest = -999; int a[100]; for (int i = 0; i < 100; i++) { scanf("%d", &a[i]); } for (int i = 0; i < 100; i++) { if (highest < a[i]) highest = a[i]; } printf("%dn", highest); for (int i = 0; i < 100; i++) { if (a[i] == highest) printf("%dn", i + 1);
  • 18. } } Problem No: 1094 Solution Code: #include <stdio.h> int main() { int n, p = 0, q = 0, r = 0, t; float e, f, g; scanf("%d", &n); while (n--) { int x; char a; scanf("%d %c", &x, &a); if (a == 'C') { p = p + x; } else if (a == 'R') { q = q + x; } else if (a == 'S') { r = r + x; } } t = p + q + r;
  • 19. e = float((p * 100.00) / t); f = float((q * 100.00) / t); g = float((r * 100.00) / t); printf("Total: %d cobaiasn", t); printf("Total de coelhos: %dn", p); printf("Total de ratos: %dn", q); printf("Total de sapos: %dn", r); printf("Percentual de coelhos: %.2f %%n", e); printf("Percentual de ratos: %.2f %%n", f); printf("Percentual de sapos: %.2f %%n", g); return 0; } Problem No: 1095 Solution Code: #include <stdio.h> int main() { int sum = 60; for (int i = 1; i <= 37; i = i+3) { printf("I=%d J=%dn", i, sum); sum = sum - 5; } return 0; } Problem No: 1096 Solution Code:
  • 20. #include <stdio.h> int main() { for (int i = 1; i <= 9; i = i + 2) { printf("I=%d J=7n", i); printf("I=%d J=6n", i); printf("I=%d J=5n", i); } return 0; } Problem No: 1097 Solution Code: #include <stdio.h> int main() { int a = 7, b = 6, c = 5; for (int i = 1; i <= 9; i = i + 2) { printf("I=%d J=%dn", i, a); printf("I=%d J=%dn", i, b); printf("I=%d J=%dn", i, c); a = a + 2; b = b + 2; c = c + 2; } return 0; }
  • 21. Problem No: 1098 Solution Code: #include <stdio.h> int main() { float i, j, a = 1.2, b = 2.2, c = 3.2; printf("I=0 J=1n"); printf("I=0 J=2n"); printf("I=0 J=3n"); for (i = 0.2; i < 1; i = i + 0.2) { printf("I=%0.1f J=%0.1fn", i, a);//SamiulHaque printf("I=%0.1f J=%0.1fn", i, b); printf("I=%0.1f J=%0.1fn", i, c); a = a + 0.2; b = b + 0.2; c = c + 0.2; } printf("I=1 J=2n"); printf("I=1 J=3n"); printf("I=1 J=4n"); a=2.2,b=3.2,c=4.2; for (i = 1.2; i < 2; i = i + 0.2) { printf("I=%0.1f J=%0.1fn", i, a);//SamiulHaque printf("I=%0.1f J=%0.1fn", i, b); printf("I=%0.1f J=%0.1fn", i, c);
  • 22. a = a + 0.2; b = b + 0.2; c = c + 0.2; } printf("I=2 J=3n"); printf("I=2 J=4n"); printf("I=2 J=5n"); return 0; } Problem No: 1099 Solution Code: #include <stdio.h> int main() { int n; scanf("%d", &n); while (n--) { int x, y, sum = 0; scanf("%d %d", &x, &y); if (x == y) { printf("0n"); } if (x > y && y % 2 == 0) { for (int i = y + 1; i < x; i = i + 2) {
  • 23. sum = sum + i; } printf("%dn", sum); } else if (x > y && y % 2 != 0) { for (int i = y + 2; i < x; i = i + 2) { sum = sum + i; } printf("%dn", sum); } else if (y > x && x % 2 == 0) { for (int i = x + 1; i < y; i = i + 2) { sum = sum + i; } printf("%dn", sum); } else if(y>x && x%2!=0) { for (int i = x + 2; i < y; i = i + 2) { sum = sum + i; } printf("%dn", sum); } }
  • 24. return 0; } Problem No: 1101 Solution Code: #include <stdio.h> int main() { int m, n; for (int i = 0; i >= 0; i++) { int sum=0; scanf("%d %d", &m, &n); if (m > 0 && n > 0) { if (m >= n) { for (int j = n; j < m + 1; j++) { printf("%d ", j); sum = sum + j; } printf("Sum=%dn", sum); } else { for (int j = m; j < n + 1; j++) { printf("%d ", j); sum = sum + j;
  • 25. } printf("Sum=%dn", sum); } } else { break; } } return 0; } Problem No: 1113 Solution Code: #include <stdio.h> int main() { for (int i = 0; i >= 0; i++) { int x, y, r; scanf("%d %d", &x, &y); r = x - y; if (r == 0) { break; } else if (r > 0) { printf("Decrescenten"); }
  • 26. else if (r < 0) { printf("Crescenten"); } } return 0; } Problem No: 1114 Solution Code: #include <stdio.h> int main() { for (int i = 0; i >= 0; i++) { int n; scanf("%d", &n); if (n == 2002) { printf("Acesso Permitidon"); break; } else { printf("Senha Invalidan"); } } return 0; } Problem No: 1115
  • 27. Solution Code: #include <stdio.h> int main() { for (int i = 0; i >= 0; i++) { int x, y; scanf("%d %d", &x, &y); if (x == 0 || y == 0) { break; } else if (x > 0 && y > 0) { printf("primeiron"); } else if (x > 0 && y < 0) { printf("quarton"); } else if (x < 0 && y < 0) { printf("terceiron"); } else if (x < 0 && y > 0) { printf("segundon"); } }
  • 28. return 0; } Problem No: 1116 Solution Code: #include <stdio.h> int main() { int n; scanf("%d", &n); while (n--) { float x, y; scanf("%f %f", &x, &y); if (y == 0) { printf("divisao impossiveln"); } else { printf("%.1fn", (x / y)); } } return 0; } Problem No: 1117 Solution Code: #include <stdio.h> int main()
  • 29. { float x, sum; int j = 1; while (j < 3) { scanf("%f", &x); if (x >= 0.0 && x <= 10.0) { sum = sum + x; j++; continue; } else { printf("nota invalidan"); continue; } } printf("media = %.2fn", sum / 2.0); return 0; } Problem No: 1118 Solution Code: #include <stdio.h> int main() { int x = 1, j = 0;
  • 30. float s[2], a, avg; while (x != 2) { if (x == 1) { while (j <= 1) { scanf("%f", &a); if (a >= 0.0 && a <= 10.0) { s[j] = a;//SamiulHaque j++; } else { printf("nota invalidan"); } } avg = (s[0] + s[1]) / 2.0; printf("media = %.2fn", avg); } printf("novo calculo (1-sim 2-nao)n"); scanf("%d", &x); j = 0; continue; } return 0;
  • 31. } Problem No: 1132 Solution Code: #include <stdio.h> int main() { int x, y, add = 0; scanf("%d %d", &x, &y); if (x == y) { printf("0"); } else if (x > y) { for (int i = y; i <=x; i++) { if (i % 13 != 0) { add = add + i; } } printf("%dn", add); } else if (x < y) { for (int i = x; i <=y; i++) { if (i % 13 != 0) {
  • 32. add = add + i; } } printf("%dn", add); } return 0; } Problem No: 1133 Solution Code: #include <stdio.h> int main() { int x, y, a = 0, b = 0; scanf("%d %d", &x, &y); if (x > y) { for (int i = y + 1; i < x; i++) { if (i % 5 == 2 || i % 5 == 3) { printf("%dn", i); } } } else if (x < y) { for (int i = x + 1; i < y; i++) { if (i % 5 == 2 || i % 5 == 3)
  • 33. { printf("%dn", i); } } } return 0;} Problem No: 1134 Solution Code: #include <stdio.h> int main() { int a = 0, b = 0, c = 0; for (int i = 1; i > 0; i++) { int n; scanf("%d", &n); if(n==1) { a++; } else if(n==2) { b++; } else if(n==3) { c++; } else if(n==4)
  • 34. { break; } else { continue; } } printf("MUITO OBRIGADOn"); printf("Alcool: %dn", a); printf("Gasolina: %dn", b); printf("Diesel: %dn", c); return 0; } Problem No: 1142 Solution Code: #include <stdio.h> int main() { int n; scanf("%d", &n); int a = 1, b = 2, c = 3; while (n--) { printf("%d ", a); printf("%d ", b); printf("%d ", c); printf("PUMn"); a = a + 4;
  • 35. b = b + 4; c = c + 4; } return 0; } Problem No: 1143 Solution Code: #include <stdio.h> int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { printf("%d %d %dn", i, i * i, i * i * i); } return 0; } Problem No:1144 Solution Code: #include <stdio.h> int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) {
  • 36. printf("%d %d %dn", i, i * i, i * i * i); printf("%d %d %dn", i, (i * i) + 1, (i * i * i) + 1); } return 0; } Problem No: 1145 Solution Code: #include <stdio.h> int main() { int x, y, c = 0; scanf("%d %d", &x, &y); for (int i = 1; i <= y; i++) { if (i % x != 0) { printf("%d ", i);//SamiulHaque } else if (i % x == 0) { printf("%dn",i); } } return 0; } Problem No: 1146 Solution Code:
  • 37. #include <stdio.h> int main() { int x; while (x != 0) { scanf("%d", &x); for (int i = 1; i <= x; i++) { if (i % x != 0) { printf("%d ", i);//SamiulHaque } else if (i % x == 0) { printf("%dn", i); } } } return 0; } Problem No:1149 Solution Code: #include <stdio.h> int main() { int n, a, sum = 0;
  • 38. scanf("%d ", &a); for (int i = 0; i >= 0; i++) { scanf("%d", &n); if (n > 0) { for (int i = a; i < a + n; i++) { sum = sum + i; } printf("%dn", sum); break; } else { continue; } } return 0; } Problem No: 1150 Solution Code: #include <stdio.h> int main() { int x, z, sum = 0, c=0;
  • 39. scanf("%d", &x); for (int i = 0; i >= 0; i++) { scanf("%d", &z); if (z <= x) { continue; } else { break; } } for (int i = 0; i >= 0; i++) { sum = x + i + sum; c++; if (sum >= z) { break; } } printf("%dn", c); return 0; } Problem No: 1151 Solution Code:
  • 40. #include <stdio.h> int main() { int n, a = 0, b = 1, c; scanf("%d", &n); if (n == 1) { printf("%n", a); } else if (n == 2) { printf("%d %dn", a, b); } else { printf("%d %d", a, b); for (int i = 2; i < n; ++i) { c = a + b; printf(" %d", c); a = b; b = c; } printf("n"); } return 0; }
  • 41. Problem No: 1153 Solution Code: #include <stdio.h> int main() { int n, fact = 1; scanf("%d", &n); if (n <= 1) { printf("1n"); } else { for (int i = 1; i <= n; i++) { fact = fact * i; } printf("%dn", fact); } return 0; } Problem No: 1154 Solution Code: #include <stdio.h> int main() { float sum = 0, a = 0;
  • 42. for (int i = 0; i >= 0; i++) { int x; scanf("%d", &x); if (x < 0) { break; } else if (x >= 0) { sum = sum + x; a++; } } printf("%.2fn", float(sum / a)); return 0; } Problem No: 1155 Solution Code: #include <stdio.h> int main() { float sum = 0; for (float i = 1; i <= 100; i++) { sum = sum + (1 / i); }
  • 43. printf("%.2fn", sum); return 0; } Problem No: 1156 Solution Code: #include <stdio.h> #include <math.h> int main() { float sum = 0; for (float i = 1, j = 0; i <= 39, j <= 20; i = i + 2, j++) { sum = sum + (i / pow(2, j)); } printf("%.2fn", sum); return 0; } Problem No: 1157 Solution Code: #include <stdio.h> int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { if (n % i == 0)
  • 44. { printf("%dn", i); } } return 0; } Problem No: 1158 Solution Code: #include <stdio.h> int main() { int n; scanf("%d",&n); while (n--) { int x, y, sum = 0; scanf("%d %d", &x, &y); if (x % 2 == 0) { for (int i = x; i < x + 2 * y; i++) { if (i % 2 != 0) { sum = sum + i; } } printf("%dn", sum);
  • 45. } else if (x % 2 != 0) { for (int i = x; i < x + 2 * y; i++) { if (i % 2 != 0) { sum = sum + i; } } printf("%dn", sum); } } return 0; } Problem No: 1159 Solution Code: #include <stdio.h> int main() { for (int i = 0; i >= 0; i++) { int x, sum = 0; scanf("%d", &x); if (x == 0) { break;
  • 46. } else { for (int i = x; i < x + 10; i++) { if (i % 2 == 0) { sum = sum + i; } else { continue; } } printf("%dn", sum); } } return 0; } Problem No: 1160 Solution Code: #include <stdio.h> int main() { int t, pa, pb, c; double ga, gb, p, q; scanf("%d", &t);
  • 47. while (t--) { c = 0; scanf("%d %d %lf %lf", &pa, &pb, &ga, &gb); p = ga / 100; q = gb / 100; while (pa <= pb) { pa = pa + (pa * p);//SamiulHaque pb = pb + (pb * q); c++; if (c > 100) { printf("Mais de 1 seculo.n"); break; } } if (c <= 100) { printf("%d anos.n", c); } } return 0;}