Ca some one please help me with aC code to allow user enter
numbers from 1 to 20 without repeating and prnt the sum of
those numbers
thnx

Answers were Sorted based on User's Feedback



Ca some one please help me with aC code to allow user enter numbers from 1 to 20 without repeating ..

Answer / asadhsheriff

int main()
{
int a[20],i,j,count=0;
memset(a,0,20);
for(;count<=20;)
{
scanf("%d",&j);
if(a[j]==0)
{
count++;
a[j]=j;
}
}
i=20(10)/2;
printf("The sum is %d",i);
}

Is This Answer Correct ?    1 Yes 0 No

Ca some one please help me with aC code to allow user enter numbers from 1 to 20 without repeating ..

Answer / douglas

I so far have nothing

Is This Answer Correct ?    0 Yes 0 No

Ca some one please help me with aC code to allow user enter numbers from 1 to 20 without repeating ..

Answer / kaiss

we will use looping for making this program.

Is This Answer Correct ?    0 Yes 0 No

Ca some one please help me with aC code to allow user enter numbers from 1 to 20 without repeating ..

Answer / sanjay bhosale

/ Duplicate.cpp : main project file.
// Program : To find duplicate no in array by traversing it only once.
#include "stdafx.h"
#include<stdio.h>
#include<malloc.h>

using namespace System;

int main(array<System::String ^> ^args)
{
int *arr;
int val = 0;
int size = 0;
printf(" \n Enter the no of elements in array :");
scanf_s("%d",&size);
arr = (int *)malloc(sizeof(int)*size);
printf("\n Enter elements in the range 1 to %d:",size);
for(int i=0;i<size;i++)
{
scanf_s("%d",&val);
if(val<1 && val>=size)
{
printf("\n enter element again :\t");
i--;
}
else
*(arr+i) = val;
}
int sum = 0;
getchar();
printf("Array is :\n");
for(int i=0;i<size;i++)
{
printf("\t %d",arr[i]);
sum+= arr[i];
}
getchar();
printf("\n sum : %d",sum);
int diff = sum-(size*(size-1)/2.0);
printf(" Duplicate element is :%d\n",diff);
getchar();
return 0;
}


Might this help you........

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

In C language what is a 'dangling pointer'?

0 Answers   Accenture,


Which of the following sorts is quickest when sorting the following set: 1 2 3 5 4 1) Quick Sort 2) Bubble Sort 3) Merge Sort

7 Answers  


What are nested functions in c?

0 Answers  


There seem to be a few missing operators ..

0 Answers  


How do i store a paragraph into a string? for example, if i input a long paragraph, the program will read the words one by one and concatenate them until no word is left.

1 Answers  






Explain what is meant by 'bit masking'?

0 Answers  


Give the output for the following program. #define STYLE1 char main() { typedef char STYLE2; STYLE1 x; STYLE2 y; clrscr(); x=255; y=255; printf("%d %d\n",x,y); }

2 Answers   ADITI,


write a program to swap two numbers without using temporary variable?

3 Answers  


How do you define a string?

0 Answers  


what are enumerations in C

0 Answers   TCS,


Write any data structure program (stack implementation)

1 Answers   HTC,


What are void pointers in c?

0 Answers  


Categories