Computer Science, asked by deaaadpoool, 1 year ago

Design a 'for' loop in such a way that when the input is given as 132, the processing inside the loop should be (1111+3333+2222 = 6666) i.e each digit from the entered number should be multiplied by 1111 and then added.

Answers

Answered by pipi
1
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a[2], i, c=0;/*the a[2] is the input assuming it to be of three digits​. i is a counting variable. c is used for the output. initial value of c is considered as 0*/
printf("please enter the desired three digit number ");
for(i=0;i<=2;i++)
{
scanf("%d",&a[i]);/*the array is being taken one digit after the other*/
}
for(i=0;i<=2;i++)
{
a[i]=a[i]*1111;
c=c+a[i];
}
printf("the answer is %d", &c);
}

deaaadpoool: I think it should be a[3] to store 3 values because a[2] can only take 2 values i.e a[0] and a[1] and BTW is there any other way by which we give the input directly like 132, instead of entering each digit individually cause that is actually the main idea of it.
pipi: then you can totally remove the scanf terms and directly initialize array as int a[3]={1,3,2}
pipi: sorry for the mistake. it should be a[3] only.
Similar questions