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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Difference between MAC vs. IP Addressing

644


Is struct oop?

585


which is conditional construct a) if statement b) switch statement c) while/for d) goto

741


What is a lvalue

668


How can I find out how much free space is available on disk?

632






In this assignment you are asked to write a multithreaded program to find the duplicates in an array of 10 million integers. The integers are between -5000,000 to 5000,000 and are generated randomly. Use 10 threads, each thread works on 1000,000 integers. Compare the time needed to accomplish the task with single thread of execution program. Do not include the time to fill the array with integers in the execution time.

2686


Why array is used in c?

554


What is the basic structure of c?

561


What is a null pointer assignment error? What are bus errors, memory faults, and core dumps?

908


What is binary tree in c?

626


What is nested structure with example?

630


write a program in C that prompts the user for today's date,tomorrow's date and display the results.Use structures for today's date,tomorrow's date and an array to hold the days for each month of the year.

4992


What are examples of structures?

601


Is c dynamically typed?

671


Is that possible to add pointers to each other?

907